setstate

Using a dynamic key to setState in React [duplicate]

穿精又带淫゛_ 提交于 2019-11-28 14:30:42
This question already has an answer here: How to use a variable for a key in a JavaScript object literal? 12 answers Reactjs setState() with a dynamic key name? 7 answers react setState with dynamic key 1 answer From an input field I am sending the value as an argument to the function that sets state. I have multiple input fields so would like to use their name (which is equal to their state key) to then use the same function and pass in the key and value to the function that sets state. here is my code. <Modal onTextChange={(text, key) => { this.setState({ event: { key: text } }) }} /> and

Can I execute a function after setState is finished updating?

让人想犯罪 __ 提交于 2019-11-28 03:01:10
I am very new to React JS (as in, just started today). I don't quite understand how setState works. I am combining React and Easel JS to draw a grid based on user input. Here is my JS bin: http://jsbin.com/zatula/edit?js,output Here is the code: var stage; var Grid = React.createClass({ getInitialState: function() { return { rows: 10, cols: 10 } }, componentDidMount: function () { this.drawGrid(); }, drawGrid: function() { stage = new createjs.Stage("canvas"); var rectangles = []; var rectangle; //Rows for (var x = 0; x < this.state.rows; x++) { // Columns for (var y = 0; y < this.state.cols;

ReactJS: Warning: setState(…): Cannot update during an existing state transition

醉酒当歌 提交于 2019-11-27 06:01:54
I am trying to refactor the following code from my render view: <Button href="#" active={!this.state.singleJourney} onClick={this.handleButtonChange.bind(this,false)} >Retour</Button> to a version where the bind is within the constructor. The reason for that is that bind in the render view will give me performance issues, especially on low end mobile phones. I have created the following code, but I am constantly getting the following errors (lots of them). It looks like the app gets in a loop: Warning: setState(...): Cannot update during an existing state transition (such as within `render` or

Flutter setState to another class?

泪湿孤枕 提交于 2019-11-26 22:59:36
I have a root class RootPage which is a StatefulWidget which is always in view. I would like to change the body in RootPage which is controlled by RootPage's currentPage Widget from different classes such as my FeedPage class and any other class that I make? Example code import 'package:flutter/material.dart'; class RootPage extends StatefulWidget { @override _RootPageState createState() => new _RootPageState(); } class _RootPageState extends State<RootPage> { FeedPage feedPage; Widget currentPage; @override void initState() { super.initState(); feedPage = FeedPage(); currentPage = feedPage; }

Can I execute a function after setState is finished updating?

余生长醉 提交于 2019-11-26 22:30:28
问题 I am very new to React JS (as in, just started today). I don't quite understand how setState works. I am combining React and Easel JS to draw a grid based on user input. Here is my JS bin: http://jsbin.com/zatula/edit?js,output Here is the code: var stage; var Grid = React.createClass({ getInitialState: function() { return { rows: 10, cols: 10 } }, componentDidMount: function () { this.drawGrid(); }, drawGrid: function() { stage = new createjs.Stage("canvas"); var rectangles = []; var

TypeError: evt.target is null in functional setState

浪子不回头ぞ 提交于 2019-11-26 21:10:20
What's the major difference bewteen these two functions? handleOnChange(evt) { this.setState(() => ({ tickerName: evt.target.value })); } handleOnChange(evt) { this.setState({ tickerName: evt.target.value }); } And why with the handleOnChange() function that change the state directly this works fine? <input type="text" value={this.state.tickerName} onChange={(evt) => this.handleOnChange(evt)} /> When I use the first function that change the state with a callback I get this error: TypeError: evt.target is null These are two different syntaxes for setState First: handleOnChange(evt) { this

Does React keep the order for state updates?

坚强是说给别人听的谎言 提交于 2019-11-26 14:50:58
I know that React may perform state updates asynchronously and in batch for performance optimization. Therefore you can never trust the state to be updated after having called setState . But can you trust React to update the state in the same order as setState is called for the same component? different components? Consider clicking the button in the following examples: 1. Is there ever a possibility that a is false and b is true for: class Container extends React.Component { constructor(props) { super(props); this.state = { a: false, b: false }; } render() { return <Button onClick={this

React setState not Updating Immediately

狂风中的少年 提交于 2019-11-26 14:41:47
I'm working on a todo application. This is a very simplified version of the offending code. I have a checkbox: <p><input type="checkbox" name="area" checked={this.state.Pencil} onChange={this.checkPencil}/> Writing Item </p> Here's the function that calls the checkbox: checkPencil(){ this.setState({ pencil:!this.state.pencil, }); this.props.updateItem(this.state); } updateItem is a function that's mapped to dispatch to redux function mapDispatchToProps(dispatch){ return bindActionCreators({ updateItem}, dispatch); } My problem is that when I call the updateItem action and console.log the state

ReactJS: Warning: setState(…): Cannot update during an existing state transition

做~自己de王妃 提交于 2019-11-26 12:51:05
问题 I am trying to refactor the following code from my render view: <Button href=\"#\" active={!this.state.singleJourney} onClick={this.handleButtonChange.bind(this,false)} >Retour</Button> to a version where the bind is within the constructor. The reason for that is that bind in the render view will give me performance issues, especially on low end mobile phones. I have created the following code, but I am constantly getting the following errors (lots of them). It looks like the app gets in a

React setState not updating state

冷暖自知 提交于 2019-11-26 12:22:47
So I have this: let total = newDealersDeckTotal.reduce(function(a, b) { return a + b; }, 0); console.log(total, 'tittal'); //outputs correct total setTimeout(() => { this.setState({dealersOverallTotal: total}); }, 10); console.log(this.state.dealersOverallTotal, 'dealersOverallTotal1'); //outputs incorrect total newDealersDeckTotal is just an array of numbers [1, 5, 9] e.g. however this.state.dealersOverallTotal does not give the correct total but total does? I even put in a timeout delay to see if this solved the problem. any obvious or should I post more code? setState() is usually