Created
May 23, 2019 14:10
-
-
Save WDever/b179a4b65a5f9fab37359b7f2ff0c69c to your computer and use it in GitHub Desktop.
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 * as React from 'react'; | |
const { useRef, useCallback } = React; | |
export function useLocalVar<T>(defaultValues: T) { | |
const state = useRef<T>(defaultValues); | |
const setState = useCallback(async (value: T) => { | |
state.current = value; | |
}, []); | |
// const setState = async (value: T) => { | |
// state.current = value; | |
// }; | |
return [state.current, setState] as [T, typeof setState]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment