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](https://private-user-images.githubusercontent.com/17745809/268460775-c7891268-26bb-45ca-98ab-b9e94471416d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTEiLCJleHAiOjE3MDM1NjI0NjMsIm5iZiI6MTcwMzU2MjE2MywicGF0aCI6Ii8xNzc0NTgwOS8yNjg0NjA3NzUtYzc4OTEyNjgtMjZiYi00NWNhLTk4YWItYjllOTQ0NzE0MTZkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFJV05KWUFYNENTVkVINTNBJTJGMjAyMzEyMjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjMxMjI2VDAzNDI0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVkNTAzYzFkZWYwZGU3NmM4NmMxNTVmYWMzMmIyZjhiODg1NDdiZjAwZDJkN2Q0OGViNGNhZWNjYWE1YTIyMjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0._EhtRPH2JGt6KMl1yxBneWizU75J7r96BQ21iPGGYYk)
Environment
- React Native version:
- React Native UI Lib version:
Affected platforms
- Android
- iOS
- Web