wix / react-native-ui-lib

UI Components Library for React Native
https://wix.github.io/react-native-ui-lib/
MIT License
6.4k stars 701 forks source link

Warning when using React.forwardRef to hand in ref to textField. #2747

Open hwhh opened 11 months ago

hwhh commented 11 months ago

Description

Warning when using React.forwardRef to hand in ref to textField.

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Check the render method of Incubator.TextField.

Related to

Code snippet


export const A = () => {
  const aRef = useRef<TextFieldRef>(null);

  return (
    <View >     
        <B onChangeText={setPhoneNumber} ref={numberRef} />
        <Button
          onPress={() => {
              console.log(numberRef?.current?.validate());
          }}
        />
      </View>

  );

}

export const B = forwardRef((props: TextFieldProps, ref: ForwardedRef<TextFieldRef>) => {

   return (
      <TextField
         ref={ref}
        {...props}
      />
    );
}

Screenshots/Video

image

Environment

Affected platforms

superjose commented 6 months ago

It's happening to me as well. Any ideas?