Best practices for passing an array from one page to another
Answered
American black bear posted this in #help-forum
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
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
8 Replies
you can use the url as state
pass everything from one page to another using query params
pass everything from one page to another using query params
@American black bear 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
normally this should be done by the client. Server states are very rare and should be only used for the things they are made for. Passing an array via the url or query params is not a good way.
Use your client side states. By the way: for order and money stuff you should never trust the client
Use your client side states. By the way: for order and money stuff you should never trust the client
@B33fb0n3 normally this should be done by the client. Server states are very rare and should be only used for the things they are made for. Passing an array via the url or query params is not a good way.
Use your client side states. By the way: for order and money stuff you should never trust the client
American black bearOP
yes, that's why I want to keep this on the server-side
@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 😦
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 reactthanks guys