I am trying to implement useContext in my react-native app but getting an error as: "undefined is not an object (evaluating 'context._context')".
here is my code(Trying to use the EmailContext):
import React, {useState} from 'react';
export const Emailcontext = React.createContext("");
const ContextStore = ({children}) => {
const [emailAddress, setEmailAddress] = useState("");
return(
<Emailcontext.Provider value={[emailAddress, setEmailAddress]}>
{children}
</Emailcontext.Provider>
);
}
export default ContextStore;
And here I wrap my app with the ContextStore:
<ContextStore>
<NavigationContainer>
<Stack.Navigator
screenOptions={{headerShown: false}}
>
<Stack.Screen name='EmailVerification' component={EmailVerification} />
<Stack.Screen name='VerifyEmailExplenation' component={VerifyEmailExplenation} />
</Stack.Navigator>
</NavigationContainer>
</ContextStore>
And then the context is undefined in this component:
import React, {useContext, useState} from 'react';
import {EmailContext} from '../ContextStore'
const EmailVerification = ({navigation}) => {
const [emailAddress, setEmailAddress] = useContext(EmailContext);
return(
**jsx element**
);
}
export default EmailVerification;
Cant find any solution for that..