Skip to content

Get Form data in a State and from there into the URLSearchParams() #779

Answered by onemanwenttomow
gregorsart asked this question in Web
Discussion options

You must be logged in to vote

Thanks for the link to the PR.

So it seems like the ultimate goal is to create a string (url) like the following

/quiz-results?barking=2&energy=2&trainability=4&good_with_children=2&good_with_other_dogs=2&protectiveness=2&shedding=2

To get there you were taking an object structured like so

{
  barking: 2,
  energy: 2,
  trainability: 4,
  good_with_children: 2,
  good_with_other_dogs: 2,
  protectiveness: 2,
  shedding: 2,
};

And converting it into a string via the URLSearchParams

e.g.

const params = new URLSearchParams(data);
`/quiz-results?${params}` // data being the object shown above

On possible solution to solve this challenge with a multi step for would be to start with an empty ob…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@gregorsart
Comment options

@onemanwenttomow
Comment options

Answer selected by onemanwenttomow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
3 participants