import * as React from 'react'; import useForceUpdate from './useForceUpdate'; type UseSyncStateProps = [() => T, (newValue: T) => void]; export default function useSyncState(initialValue: T): UseSyncStateProps { const ref = React.useRef(initialValue); const forceUpdate = useForceUpdate(); return [ () => ref.current, (newValue: T) => { ref.current = newValue; // re-render forceUpdate(); }, ]; }