Can't find variable : MyContext in React Native : How to use Context?

Viewed 31

I tried to use useContext in my React Native - Expo app to get an array from a screen in a child component, but it tells me Can't find variable : RealContext

What i would like to do :

https://www.w3schools.com/react/showreact.asp?filename=demo2_react_context2

What I have done :

My screen AuditRealisationScreen

const RealContext = createContext();
const [listIdVictimes, setListIdVictimes] = useState('please test');
[...]
return (
    <RealContext.Provider value={listIdVictimes}>
        <RealisationChapitreComponent/>
    </RealContext.Provider>
)

RealisationChapitreComponent > [...] > RealisationQuestionComponent

In my component RealisationQuestionComponent

const listTest = useContext(RealContext);
[...]
return (
    <Text> {listTest} </Text>
)

Can it work this way?

0 Answers
Related