wix / react-native-ui-lib

UI Components Library for React Native

Home Page:https://wix.github.io/react-native-ui-lib/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

hwhh opened this issue · comments

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

  • Components
  • Demo
  • Docs
  • Typings

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

  • React Native version:
  • React Native UI Lib version:

Affected platforms

  • Android
  • iOS
  • Web