#State vs Router.query?

3 messages · Page 1 of 1 (latest)

shut heron
#

On my homepage I have a form with 2 questions. Using useState to set the values and router.push({query:{}}) to bring them to /page2 to complete 5 more questions. To get the values from the 2 questions on the homepage I'm using const {foo} = router.query on /page2.

Is this practice ok? Should I be getting those values from the 'state' instead of router.query?

signal fractal
#

You can go either route, but IMO you shouldn't pass user data around in the URL. Query params are generally used for GET requests, and this sounds like more of a POST situation. Use the router and the URL for routes and page options, e.g. orderby=date&order=asc, and keep user data in state.

shut heron
#

Thank you @signal fractal I appreciate it