react-native-ui-lib
react-native-ui-lib copied to clipboard
Warning when using React.forwardRef to hand in ref to textField.
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
Environment
- React Native version:
- React Native UI Lib version:
Affected platforms
- [ ] Android
- [ ] iOS
- [ ] Web
It's happening to me as well. Any ideas?
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.