react-navigation / hooks

React hooks for convenient react-navigation use
https://reactnavigation.org
MIT License
576 stars 36 forks source link

useNavigation not working #66

Closed luizandrends closed 4 years ago

luizandrends commented 4 years ago

function App(){ const navigation = useNavigation() <Stack.Navigator screenOptions={{ headerStyle: { backgroundColor: '#5F27CD' }, headerTintColor: '#fff', headerBackTitleVisible: false, headerLeftContainerStyle: { marginLeft: 17 }, }} initialRouteName='Tabs'

<Stack.Screen name='somename' component={somepage} options={{ title: 'sometitle', headerLeft: () => ( <TouchableOpacity onPress={() => {navigation.navigate('somepage')}}>

), }} /> </Stack.Navigator } Return me this error:

Error: Couldn't find a navigation object. Is your component inside a screen in a navigator?

This error is located at: in AppRoutes (at routes.tsx:112) in Routes (at App.tsx:149) in EnsureSingleNavigator (at BaseNavigationContainer.tsx:268) in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:39) in ThemeProvider (at NavigationContainer.tsx:38) in ForwardRef(NavigationContainer) (at App.tsx:147) in BgTracking (at renderApplication.js:40) in RCTView (at AppContainer.js:101) in RCTView (at AppContainer.js:119) in AppContainer (at renderApplication.js:39)

useNavigation useNavigation.tsx:18:6 AppRoutes routes.tsx:42:21 renderRoot

runRootCallback

forEach

Refresh.performReactRefresh setUpReactRefresh.js:43:6 setTimeout$argument_0 require.js:609:10 callFunctionReturnFlushedQueue

slorber commented 4 years ago

As it is displayed in the README in big bold chars, this project should not be used with react-navigation v5