1
I started to study context api now, I believe I am making my code with the same structure as the tutorials, but the value target Component receives nothing, there is only a blank where it should have it.
import React, { Component } from 'react';
const CarContext = React.createContext();
function context(){
return(
<CarContext.Provider value='car'>
</CarContext.Provider>
);
}
function App(){
return(
<CarContext.Consumer>
{value => (
<p>a{value}</p>
)}
</CarContext.Consumer>
)
}
export default App;
What is missing for the code to work?
CarContext.Provider
andCarContext.Consumer
what these two components would be?– novic
are the context Provider and Consumer, which are the components of sending and receiving global data
– jonathas fonseca
Are you seeing these components as? because the
Consumer
really doesn’t do anything!– novic
Consumer shows what’s inside it, I tidied up, actually had forgotten to call the context function before it, calling it worked
– jonathas fonseca