Next.js Discord

Discord Forum

React Context should really be as lowest as possible?

Unanswered
Bigheaded ant posted this in #help-forum
Open in Discord
Bigheaded antOP
I am trying to learn Next building a Slotlist application, and on my front end i am building a dashboard page, when i was learning react i just found fantastic the use of context api, because i could no longer have to worry about passing data throught the component hierarchy, i could just paste the provider on the root component and that's just fine, but when i started to learn Next.js, the documentation tells us to insert the context as lowest as possible into the component hierarchy, isn't that oppositive of what context should be insert at? The way i thinked about building the application, that most of the child component will have to use the same object to get the user properties, was to add the context on Layout at app folder and use it to handle the authentication, if the profile is filled, then the context/root component will push to dashboard, otherwise it will push to login page.

11 Replies

Bigheaded antOP
theme provider only wraps children and not HTML is not kinda really that deep :''
stuff thats crucial for the whole app like themes and auth ofc can be put on the top layout level
but what they mean is like, form contexts, or component-level contexts
i think that already goes with react fundamentals too
if the context is only going to be consumed within a component, don't put it at the app's layout