ant-design/components/table/hooks/useSyncState.ts

18 lines
459 B
TypeScript
Raw Normal View History

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