Created
March 5, 2019 21:11
-
-
Save felipefunes/11a42da3d996d20edc53a4a66b5b5ce9 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
// GOOD! Place the condition inside the Hook | |
useEffect(() => { | |
if (posts === null) { | |
// This will run only if posts are not still fetched. | |
// If you mount this component more than once, | |
// the request won't beexecuted again | |
getPosts(); | |
} | |
}, []); // Besides, with the empty array this Effect just run once | |
// BAD! Wrapping the Effect insithe the condition | |
if (posts === null) { | |
useEffect(() => { | |
getPosts(); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment