The main application looks like this:
import Cookies from 'js-cookie';
function App() {
let cookie = Cookies.get('mycookie');
return (
<>
<Router>
<div>
{<Switch>
<Route path="/comp1">
<Comp1 />
</Route>
<Route path="/comp2">
<Comp2 />
</Route>
</Switch>
</div>
</Router>
</div>
);
}
As you can see, in the main app Im reading the cookie. Now, all the components will need to access the cookie. How can I make the components to read the cookie from the main app? Of course I could read the cookie by using "Cookies.get". But as Im doing other things in App.js than only reading the cookie, I would prefer to do operations once in App.js and then share all this with components.
<Comp1 cookie={cookie} />and usethis.props.cookiein yourComp1function Comp1(props) { ... props.cookie; }