Created
February 7, 2023 20:58
-
-
Save make-github-pseudonymous-again/6cc1643900f021ae11dd0baabd287263 to your computer and use it in GitHub Desktop.
Can `useDeferredValue` be built on top of `useTransition`?
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
import {useEffect, useState, useTransition} from 'react'; | |
export const useDeferredValue = (value) => { | |
const [, startTransition] = useTransition(); | |
const [deferredValue, setDeferredValue] = useState(value); | |
useEffect(() => { | |
startTransition(() => { | |
setDeferredValue(value); | |
}); | |
}, [value]) | |
return deferredValue; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment