mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 04:36:19 +08:00
221d404986
* fix: 4.0 table filters value may be previous * create a sync variable to resolve async 'setFilteredKeys' * useSyncState to fix 'setFilteredKeys' async * new line * new line * add , * removed 'setFilteredKeys' and re-render useSyncState * menu must be a array
18 lines
459 B
TypeScript
18 lines
459 B
TypeScript
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);
|
|
},
|
|
];
|
|
}
|