Skip to content

Commit 1fa4adc

Browse files
committed
fix: useExternRef use state
1 parent 878d053 commit 1fa4adc

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

packages/vkui/src/hooks/useExternRef.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ class ExternalRef<T> implements React.RefObject<T | null> {
4646
export function useExternRef<T>(
4747
...externRefs: Array<React.Ref<T> | undefined | false>
4848
): 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-
}
49+
const [externalRefs] = React.useState(() => new ExternalRef(externRefs));
50+
externalRefs.updateExternRefs(externRefs);
5551

56-
return ref.current;
52+
return externalRefs;
5753
}

0 commit comments

Comments
 (0)