Next.js Discord

Discord Forum

Best practices for passing an array from one page to another

Answered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
Hey everyone, I have a server-side rendered page where the user needs to select some options before proceeding to the order page. I’m wondering if there’s a way to share everything the user has selected and make a request on the order page to calculate the total amount.

For example: I select option A and proceed to the order page. On the order page, I need to calculate the total for A (and potentially for B, C, or D if there are other selections).

How can I achieve this? The only solution I can think of is making the page client-side and using state management like Redux or another approach
Answered by American black bear
just added router.refresh()
View full answer

8 Replies

you can use the url as state
pass everything from one page to another using query params
@American black bear you should use client side state management
@James4u <@713793871401844816> you should use client side state management
American black bearOP
this is already fixed
the problem now is: I have a list of products stored in cookies. My server-side page retrieves this info and sends a POST request to the API. The API returns some data and I format this data. After formatting, I send the information to the client, whose responsibility is to simply display the data. But for now, I can't achieve this because I have a delete button that removes a product. After the product is deleted on the client side, the server side doesn't hear this change so the product never disappears from the page 😦
American black bearOP
just added router.refresh()
Answer
American black bearOP
with transition using useTransition from react
thanks guys