recoil#useRecoilState_TRANSITION_SUPPORT_UNSTABLE TypeScript Examples
The following examples show how to use
recoil#useRecoilState_TRANSITION_SUPPORT_UNSTABLE.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useRecoilStateDeferred.ts From nextclade with MIT License | 6 votes |
export function useRecoilStateDeferred<T>(recoilState: RecoilState<T>): [T, SetterOrUpdater<T>] {
const [initialValue, setRecoilValue] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(recoilState)
const [value, setValue] = useState(initialValue)
const [, startTransition] = useTransition()
const setValueDeferred = useCallback(
(valOrUpdater: ValOrUpdater<T>) => {
setValue(valOrUpdater)
startTransition(() => {
setRecoilValue(valOrUpdater)
})
},
[setRecoilValue],
)
return [value, setValueDeferred]
}