UNPKG

272 BJavaScriptView Raw
1import { useEffect, useRef, useState } from 'react';
2export function useRefState(initialState) {
3 const [state, setState] = useState(initialState);
4 const ref = useRef(state);
5 useEffect(() => {
6 ref.current = state;
7 }, [state]);
8 return [state, setState, ref];
9}
\No newline at end of file