Next.js Discord

Discord Forum

Pass Data to Next Screen

Answered
Snowshoe posted this in #help-forum
Open in Discord
SnowshoeOP
Guys, I want to send some data to next page, and I dont want to show it in the url

I want to send " item " variable which is a Map/Dictionary.
the page it has to send is "/product"
Answered by ᴉuɐpɹɐɐ
you can store item inside a React context that you wrap your /layout.tsx in. That way when you move from / to /product , the data will stay there since it doesnt rerender /layout.tsx.

Then on each page, you can consume the context by using use to grab the item variable.

See here:
https://react.dev/reference/react/createContext#creating-context
View full answer

2 Replies

@Snowshoe Guys, I want to send some data to next page, and I dont want to show it in the url I want to send " item " variable which is a Map/Dictionary. the page it has to send is "/product"
you can store item inside a React context that you wrap your /layout.tsx in. That way when you move from / to /product , the data will stay there since it doesnt rerender /layout.tsx.

Then on each page, you can consume the context by using use to grab the item variable.

See here:
https://react.dev/reference/react/createContext#creating-context
Answer
SnowshoeOP
I will check it out