{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react/issues/5958","labels_url":"https://api.github.com/repos/facebook/react/issues/5958/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react/issues/5958/comments","events_url":"https://api.github.com/repos/facebook/react/issues/5958/events","html_url":"https://github.com/facebook/react/issues/5958","id":130485236,"number":5958,"title":"Enhancement: Build in a way to generate a function that sets some state variable","user":{"login":"moodysalem","id":7897876,"avatar_url":"https://avatars.githubusercontent.com/u/7897876?v=3","gravatar_id":"","url":"https://api.github.com/users/moodysalem","html_url":"https://github.com/moodysalem","followers_url":"https://api.github.com/users/moodysalem/followers","following_url":"https://api.github.com/users/moodysalem/following{/other_user}","gists_url":"https://api.github.com/users/moodysalem/gists{/gist_id}","starred_url":"https://api.github.com/users/moodysalem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moodysalem/subscriptions","organizations_url":"https://api.github.com/users/moodysalem/orgs","repos_url":"https://api.github.com/users/moodysalem/repos","events_url":"https://api.github.com/users/moodysalem/events{/privacy}","received_events_url":"https://api.github.com/users/moodysalem/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-01T21:11:51Z","updated_at":"2016-02-01T21:28:39Z","closed_at":"2016-02-01T21:16:33Z","body":"I created [this mixin](https://github.com/moodysalem/set-state-function-mixin) this morning to handle creating functions that just call setState if the component is mounted, but it would be nice if it was just built in to the React component since I think it's a pretty common pattern to handle UI events by just setting some state variable."},"comment":{"url":"https://api.github.com/repos/facebook/react/issues/comments/178202400","html_url":"https://github.com/facebook/react/issues/5958#issuecomment-178202400","issue_url":"https://api.github.com/repos/facebook/react/issues/5958","id":178202400,"user":{"login":"jimfb","id":9595985,"avatar_url":"https://avatars.githubusercontent.com/u/9595985?v=3","gravatar_id":"","url":"https://api.github.com/users/jimfb","html_url":"https://github.com/jimfb","followers_url":"https://api.github.com/users/jimfb/followers","following_url":"https://api.github.com/users/jimfb/following{/other_user}","gists_url":"https://api.github.com/users/jimfb/gists{/gist_id}","starred_url":"https://api.github.com/users/jimfb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimfb/subscriptions","organizations_url":"https://api.github.com/users/jimfb/orgs","repos_url":"https://api.github.com/users/jimfb/repos","events_url":"https://api.github.com/users/jimfb/events{/privacy}","received_events_url":"https://api.github.com/users/jimfb/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T21:28:39Z","updated_at":"2016-02-01T21:28:39Z","body":"Without `isMounted`, you could just write \r\n\r\n`React.DOM.button({ onClick: () => this.setState({modalOpen: true})})` (without mixin)\r\n`React.DOM.button({ onClick: this.setStateFunction('modalOpen', true) }),` (with mixin)\r\n\r\nThe version without the mixin is syntactically shorter, and more readable (doesn't depend on the details of a mixin).  Therefore, I still wouldn't recommend it.  But if you find it useful, more power to you!"}}