mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 21:28:09 +08:00
5c99a5ee49
* type: fix .dumi typing error * type: fix React.Key type error * type: fix React.Key type error * type: fix React.Key type error * type: fix React.Key type error * Apply suggestions from code review Signed-off-by: afc163 <afc163@gmail.com> * fix: test case * fix: test case * chore: use @types/react latest version * Apply suggestions from code review Signed-off-by: afc163 <afc163@gmail.com> * chore: update form def * chore: more ts * chore: revert demo ts * chore: bump ver * chore: fix more * chore: fix demo * chore: back of ci * chore: fix ts * chore: fix ts * chore: part of it * chore: fix ts * chore: bump ver * chore: fix lint * chore: fix * test: update test --------- Signed-off-by: afc163 <afc163@gmail.com> Co-authored-by: 二货机器人 <smith3816@gmail.com>
20 lines
470 B
TypeScript
20 lines
470 B
TypeScript
import * as React from 'react';
|
|
|
|
import useForceUpdate from './useForceUpdate';
|
|
|
|
type UseSyncStateProps<T> = readonly [() => T, (newValue: T) => void];
|
|
|
|
export default function useSyncState<T>(initialValue: T): UseSyncStateProps<T> {
|
|
const ref = React.useRef<T>(initialValue);
|
|
const forceUpdate = useForceUpdate();
|
|
|
|
return [
|
|
() => ref.current,
|
|
(newValue: T) => {
|
|
ref.current = newValue;
|
|
// re-render
|
|
forceUpdate();
|
|
},
|
|
] as const;
|
|
}
|