Created
February 26, 2020 23:18
-
-
Save estrattonbailey/5aa4aea59934ad8169d22c24ac5ba227 to your computer and use it in GitHub Desktop.
Delays updating of values.
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 Lag<T>({ | |
value, | |
ttl, | |
children, | |
}: { | |
value: T; | |
ttl: number; | |
children(value: T): any; | |
}) { | |
const [cache, setCache] = React.useState(value); | |
React.useEffect(() => { | |
setTimeout(() => { | |
setCache(value); | |
}, ttl); | |
}, [value]); | |
return children(cache); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment