I have the following code:
const menuItemRefs = useRef<{ [key: number]: typeof View }>({}); const { isMenuVisible } = useTopMenuContext(); useEffect(() => { const onBackPress = () => { if (isMenuVisible) { menuItemRefs.current[0].setNativeProps({ hasTVPreferredFocus: true }); return false; } return true; }; const backHandler = BackHandler.addEventListener('hardwareBackPress', onBackPress); return () => backHandler.remove(); }, []);
The code works perfectly but TypeScript tells me:
Property 'setNativeProps' does not exist on type 'ForwardRefExoticComponent<Pick<any, string | number | symbol> & RefAttributes>'.
The ref is returned by a plain React Native View
. How can I type this properly to remove the error?