Change BG using React State
Hey everyone,
So I have a page with different radio buttons
bg1, bg2,....bg10
That page is in a different route
For eg: /themes/
Now whenever the user changes the radio button
I want to change the background image of the whole document with user type
How can I do this in React?
3 Replies
You should store the state in a global element like the dom or global state so it does not depend on the path.
Yep, you can use Context API or some other library, like zustand
+1 for raising the state
If the background will change for only one specific route (along with that route's subroutes), you may want to apply that change with a layout file and move the route to a route group 😄
https://nextjs.org/docs/app/building-your-application/routing/route-groups
Routing: Route Groups | Next.js
Route Groups can be used to partition your Next.js application into different sections.