Last active
February 25, 2020 13:33
-
-
Save dani-mp/f61bea189a9b16259171851fd7cde994 to your computer and use it in GitHub Desktop.
React Navigation (v1/2/3/4) Navigator wrapped in a React Context Provider
very helpful. Thanks.
Silly question how can I console.log data inside one of the views? Any ideas on what I'm doing wrong here? With the code below I am trying to console.log(this.context) and get blank object {}
const BookContext = React.createContext();
class BookProvider extends Component {
state = {
name: 'BATMAN'
}
render() {
return (
<BookContext.Provider
value={{
...this.state,
name: this.state.name
}}>
{this.props.children}
</BookContext.Provider>
)
}
}
const Consumer = BookContext.Consumer;
//root stack
const RootStack = createStackNavigator({
MainStack: MainStack,
AddBookStack: AddBookStack,
EditPhotosStack: EditPhotosStack,
CameraStack: CameraStack,
AllGuidesStack: AllGuidesStack, //required to open guides from books view - dnd
}, {
mode: 'modal',
headerMode: 'none',
}, { headerLayoutPreset: 'center' });
const RootStackWithContext = props => (
<BookProvider>
<RootStack {...props} />
</BookProvider>
);
RootStackWithContext.router = RootStack.router;
//------------------------------ drawer -------------------------------//
const DrawerStack = createDrawerNavigator({
RootStack: RootStackWithContext,
RootGuidesStack: RootGuidesStack,
}, {
drawerPosition: 'left',
drawerType: 'front',
overlayColor: global.colorPurpleAlpha,
contentComponent: DrawerMenu,
});
Hi, @barrylachapelle. I can't see any console.log
statement in your code.
thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Aldisss check code and comments of lines 47 and 51.