We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 878d053 commit 1fa4adcCopy full SHA for 1fa4adc
packages/vkui/src/hooks/useExternRef.ts
@@ -46,12 +46,8 @@ class ExternalRef<T> implements React.RefObject<T | null> {
46
export function useExternRef<T>(
47
...externRefs: Array<React.Ref<T> | undefined | false>
48
): React.RefObject<T | null> {
49
- const ref = React.useRef<ExternalRef<T> | null>(null);
50
- if (ref.current === null) {
51
- ref.current = new ExternalRef(externRefs);
52
- } else {
53
- ref.current.updateExternRefs(externRefs);
54
- }
+ const [externalRefs] = React.useState(() => new ExternalRef(externRefs));
+ externalRefs.updateExternRefs(externRefs);
55
56
- return ref.current;
+ return externalRefs;
57
}
0 commit comments