Skip to content

Commit

Permalink
Initialize preservedControlledValueRef with value (#7099)
Browse files Browse the repository at this point in the history
We got an error from users about'shown' in
useFloatingWithInteractions hook

TypeError: Uncaught TypeError: Cannot read properties of undefined (reading 'shown')

I wasn't able to catch this locally, or in test env, but
to make sure preservedControlledValueRef can't be undefined
if value is defind we give it a value.
  • Loading branch information
mendrew authored Jul 5, 2024
1 parent d52c15f commit f49dd16
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vkui/src/hooks/useEnsuredControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function useCustomEnsuredControl<V = any>({
}: UseCustomEnsuredControlProps<V>): [V, React.Dispatch<React.SetStateAction<V>>] {
const isControlled = value !== undefined;
const [localValue, setLocalValue] = React.useState(defaultValue);
const preservedControlledValueRef = React.useRef<V>();
const preservedControlledValueRef = React.useRef(value);

useIsomorphicLayoutEffect(() => {
preservedControlledValueRef.current = value;
Expand Down

0 comments on commit f49dd16

Please sign in to comment.