{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react/issues/122","labels_url":"https://api.github.com/repos/facebook/react/issues/122/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react/issues/122/comments","events_url":"https://api.github.com/repos/facebook/react/issues/122/events","html_url":"https://github.com/facebook/react/issues/122","id":15903026,"number":122,"title":"Pending state updates may be confusing","user":{"login":"spicyj","id":6820,"avatar_url":"https://avatars.githubusercontent.com/u/6820?v=3","gravatar_id":"","url":"https://api.github.com/users/spicyj","html_url":"https://github.com/spicyj","followers_url":"https://api.github.com/users/spicyj/followers","following_url":"https://api.github.com/users/spicyj/following{/other_user}","gists_url":"https://api.github.com/users/spicyj/gists{/gist_id}","starred_url":"https://api.github.com/users/spicyj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spicyj/subscriptions","organizations_url":"https://api.github.com/users/spicyj/orgs","repos_url":"https://api.github.com/users/spicyj/repos","events_url":"https://api.github.com/users/spicyj/events{/privacy}","received_events_url":"https://api.github.com/users/spicyj/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/react/labels/Component:%20Core","name":"Component: Core","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":29,"created_at":"2013-06-23T21:53:07Z","updated_at":"2015-03-16T07:47:37Z","closed_at":null,"body":"If you have\r\n\r\n```\r\ncomponentWillReceiveProps: function() {\r\n    this.setState({x: this.state.x + 1});\r\n    this.setState({x: this.state.x + 1});\r\n}\r\n```\r\n\r\nthen `x` will only be incremented once because the new state will just be stored in `_pendingState` until `receiveProps` finishes. After my refactoring in #115, this will never increment twice, which is probably confusing.\r\n\r\nMaybe this isn't a bug. We can fix this behavior by instead updating this.state immediately (but still updating the UI later). Right now I can't think of any situations where having this.state out of sync with the UI is a problem.\r\n\r\n@vjeux suggested I open an issue, so here I am. Probably easiest for me to fix while updating #115 though."},"comment":{"url":"https://api.github.com/repos/facebook/react/issues/comments/81471340","html_url":"https://github.com/facebook/react/issues/122#issuecomment-81471340","issue_url":"https://api.github.com/repos/facebook/react/issues/122","id":81471340,"user":{"login":"markmarijnissen","id":1287693,"avatar_url":"https://avatars.githubusercontent.com/u/1287693?v=3","gravatar_id":"","url":"https://api.github.com/users/markmarijnissen","html_url":"https://github.com/markmarijnissen","followers_url":"https://api.github.com/users/markmarijnissen/followers","following_url":"https://api.github.com/users/markmarijnissen/following{/other_user}","gists_url":"https://api.github.com/users/markmarijnissen/gists{/gist_id}","starred_url":"https://api.github.com/users/markmarijnissen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markmarijnissen/subscriptions","organizations_url":"https://api.github.com/users/markmarijnissen/orgs","repos_url":"https://api.github.com/users/markmarijnissen/repos","events_url":"https://api.github.com/users/markmarijnissen/events{/privacy}","received_events_url":"https://api.github.com/users/markmarijnissen/received_events","type":"User","site_admin":false},"created_at":"2015-03-16T07:47:37Z","updated_at":"2015-03-16T07:47:37Z","body":"Hey everybody,\r\n\r\nCheck out Meteor's implementation of their Tracker. \r\n\r\nThey queue all state changes and flush on a requestAnimationFrame, unless you explicitly call Tracker.flush() to proces all pending changes.\r\n\r\nif you do\r\n```\r\nbob_bank_account -= 10;\r\nalice_bank_account += 10;\r\n```\r\n\r\nyou will never end up with an invalid state (i.e. 10$ appearing or dissapearing out of nowhere). Either all changes are pending, or they are all resolved (using Tracker.flush, or at the end of the event cycle).\r\n\r\nSo, to summarize:\r\n* `setState` should read as `enqueueStateChange`\r\n* Add a method to process queue if you want to force the state changes immediatly (for example when you need in-between results (updated state) for you calculations)"}}