Skip to content

Instantly share code, notes, and snippets.

@WDever
Created May 23, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WDever/b179a4b65a5f9fab37359b7f2ff0c69c to your computer and use it in GitHub Desktop.
Save WDever/b179a4b65a5f9fab37359b7f2ff0c69c to your computer and use it in GitHub Desktop.
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