S
Supabase8mo ago
RBGDEV

Looking for solid examples of Supabase Context Providers + Hooks

Any links to githubs or docs that would help me properly architect Context providers and hooks i could wrap my pages or layout with. Goals: - looking to capture things from the database that i can grab with something like useContext() or anything similar so i dont have to make calls on every page that needs it and pass it down a long chain of components I'm using Next.js 15.1 app router.
5 Replies
RBGDEV
RBGDEVOP8mo ago
for context i normally work on frontend so architecting how to share data across my app where needed, redirect to other pages efficiently isnt something im fully aware of from an architecture perspective in my app right now im just calling things each time i need them at the page level then passing them down however long the chain is, but some things i need in so many places almost like feature flag type things
silentworks
silentworks8mo ago
I'd suggest you follow the app router ways and how it's noted in the Supabase docs. Anything outside of that is asking for a can of worms that you won't get much help with.
Marcus
Marcus8mo ago
That wont work due to RSCs. Unless you plan on forcing everything client side but at that point you should use the pages router, and add a provider in _app.tsx
anything similar so i dont have to make calls on every page that needs it and pass it down a long chain of components
So the new React 19 paradigm should allow you to fetch the data all the way down in the component that needs it, avoiding the need for prop drilling. Using the new cache (from react) function allows you to also call the same fetch request in multiple places in a request roundtrip only fetching the resource once. This video really made it click for me, probably have to watch it a couple of times https://youtu.be/CvAySC5ex9c?feature=shared
Terry
Terry8mo ago
+1 on that video, it's great and describes the right way to do it! You want to abstract common fetching to hooks and run them in each component. Good callout that I'm pretty sure we don't have an example of this in our npx create-next-app -e with-supabase template. I'll make a note and see if it makes sense to add.
RBGDEV
RBGDEVOP8mo ago
thank you all!

Did you find this page helpful?