Created
April 16, 2017 02:58
-
-
Save ronsuez/b986b6c7852a0c1cefd6cf04ae46b0e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shouldIkeepSomethingInReactState() { | |
if (canIcalculateItFromProps()) { | |
// Don't duplicate data from props in state. | |
// Calculate what you can in render() method. | |
return false; | |
} | |
if (!amUsingItInRenderMethod()) { | |
// Don't keep something in the state | |
// if you don't use it for rendering. | |
// for example, API subscriptions are | |
// better off as custom private fields | |
// or variables in external modules. | |
return false; | |
} | |
// You can use React state from this! | |
return true; | |
// taken from: https://twitter.com/dan_abramov/status/749710501916139520 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment