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