mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 14:29:33 +08:00
6d685c7e8a
* fix: useSyncState logic * add test case
18 lines
465 B
TypeScript
18 lines
465 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<object | null>(null);
|
|
|
|
return [
|
|
() => filteredKeysRef.current,
|
|
(newValue: T) => {
|
|
filteredKeysRef.current = newValue;
|
|
// re-render
|
|
forceUpdate({});
|
|
},
|
|
];
|
|
}
|