Created
October 2, 2021 05:56
-
-
Save Pyrolistical/e8d8bbecb50fea9cb2504a0f1918345a to your computer and use it in GitHub Desktop.
https://blog.battlefy.com/how-to-escape-react-hooks-hell-a66c0d142c9e Unnecessary useEffect
This file contains hidden or 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
// BEFORE | |
const [state, setState] = useState(); | |
useEffect(() => { | |
setState(calculateInitialState()); | |
}, []); | |
// AFTER | |
const [state, setState] = useState(calculateInitialState); |
This file contains hidden or 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
// BEFORE | |
const [state, setState] = useState(); | |
useEffect(() => { | |
setState('loading'); | |
}, []); | |
// AFTER | |
const [state, setState] = useState('loading'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment