I get the error
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
Which I do not understand. I am using useSelector() throughout my App without any Problems. And when using it in this component, it breaks. Why is that?
import { useSelector } from "react-redux";
const DrawerContent = (props) => {
const someVar = useSelector((state) => state.foo.bar);
return (
<DrawerContentScrollView {...props}>
<Foo>{someVar}</Foo>
<DrawerItemList {...props}>
<DrawerItem
label="Kitten"
onPress={() => props.navigation.navigate("Cat")}
/>
<DrawerItem
label="Doggo"
onPress={() => props.navigation.navigate("Dog")}
/>
</DrawerItemList>
</DrawerContentScrollView>
);
};
<DrawerContent /> is used like this
const DrawerNavigator = () => {
return <Drawer.Navigator
drawerContent={props => DrawerContent(props)}>
<Drawer.Screen name='A' component={TabNavigator} />
<Drawer.Screen name='B' component={AStack} />
<Drawer.Screen name='C' component={BStack} />
</Drawer.Navigator>
}