Last active
August 25, 2021 05:58
-
-
Save dlh01/9434f82f649da690a34cb4421aeae92e 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
const useEffectOnceOnDemand = (effect) => { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
if (1 === count) { | |
effect(); | |
} | |
}); | |
return () => setCount((prev) => Math.min(2, prev + 1)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment