I can migrate some of my pages to this new feature, but not all straight away: my layout has a breadcrumbs prop and an actions placeholder. It’s very cool to have those options though, and for my specific case I think I have no choice but to look for Context - which is cool.
I’ll try hook before context, great idea, I’m reluctant to play with contexts x).
My actions placeholder is a spot at the same level as the breadcrumbs.
We’re building an application for school management, on the pages where we edit a Teacher, a Student, a Customer, a Session, we systematically have a button at the top to let us delete the entity we’re currently editing.
On some of those pages we have extra buttons, so we expect these to be dynamic :).
( there’s a preprod coming as soon as I manage to fix my netlify deploy, you’d see in context how we use the actions placeholder )
What ‘kind’ of context can be used in the set attribute? (I don’t think it’s the React hook useContext as I don’t see any mention of Providers/Consumers.)
I’ve searched through the docs and forums, but besides GQL related results, I didn’t find much about context and I don’t understand how to integrate the context needed for the breadcrumbs example above.
I think that could be extremely useful, but I actually ended up here after trying to display the current page’s title in the Layout component. Is there a way to add additional properties to a Route element in web/src/Routes.js that could be consumed in the parent layout? (I tried: useParams, useLocations, useRouterState.)
There are quite a few contexts to keep track of, but this one is React context. The Provider/Consumer is kind of implied, but to make things more explicit, in @Tobbe’s breadcrumbs example, the Set component would have the BreadcrumbsProvider:
You’ve got to be careful using context like this though. Context is better for dependency management—just passing something down the tree. Once you start mutating context, you get a lot of rerenders and might blow away your state further down the tree.
Passing information from the pages up to layouts is a very common thing to want to do. And I’ve been using context for that without issue in a lot of places. But if you do start noticing performance issues (I haven’t) Dom is right that contexts do often result in more re-renders than you might at first realize.
Thanks for asking. If more people start asking about this, maybe we should be thinking of a way to provide a built in solution for this.
Thank you both for the quick and informative replies. I have it wired up and I’m working on testing it out. I don’t think it’ll get very complicated for this addition, but I’ll definitely keep an eye on the re-renders.