Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

react useRef typescript child forwardedRef type

$
0
0

I'm forwarding a ref to Child component as per the react docs: https://reactjs.org/docs/forwarding-refs.html.

const userRef = useRef<TextInput>(null);interface IWrappedComponent {  ref?: RefObject<TextInput>;}const WrappedComponent = React.forwardRef((props: IWrappedComponent, ref) => {  return <LogProps {...props} forwardedRef={ref} />;});interface ILogProps {  innerRef?: RefObject<TextInput>;}

However I'm getting a type error for forwardedRef. I'm using RefObject<TextInput> for type, but am getting the following:

Type 'ForwardedRef<unknown>' is not assignable to type 'RefObject<TextInput>'.  Type 'null' is not assignable to type 'RefObject<TextInput>'.

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>