react-native-ui-lib icon indicating copy to clipboard operation
react-native-ui-lib copied to clipboard

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

Open hwhh opened this issue 2 years ago • 1 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

  • [X] 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

hwhh avatar Sep 16 '23 17:09 hwhh

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

superjose avatar Feb 23 '24 11:02 superjose

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 31 '25 23:01 stale[bot]