Created
October 2, 2021 06:12
-
-
Save Pyrolistical/cfb4840c8154fa06cb3c4ee9b0602ad3 to your computer and use it in GitHub Desktop.
https://blog.battlefy.com/how-to-escape-react-hooks-hell-a66c0d142c9e Unnecessary useEffect and useState for computed value based on prop
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
// BEFORE | |
const [costlyValue, setCostlyValue] = setState(); | |
useEffect(() => { | |
setCostlyValue(computedCostlyValue(props.someParam)); | |
}, [props.someParam]); | |
// AFTER | |
const costlyValue = useMemo(() => computedCostlyValue(props.someParam), [props.someParam]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment