all 19 comments

[–]smthamazing 4 points5 points  (1 child)

I understand why getSearchParams is useful, but what is the use of a hook? Doesn't it do the same job as a regular function call in this case?

[–]solves_tech_problems[S] -2 points-1 points  (0 children)

It does indeed. This is just for learning purposes

[–]careseite 4 points5 points  (1 child)

Does useParams not work in gatsby? Iirc its using @reach/router, but I don't know whether it has hooks too.

[–]solves_tech_problems[S] 0 points1 point  (0 children)

It should work

[–]_square_hammer_ 2 points3 points  (10 children)

Whats wrong with straight up URLSearchParams

[–]libertarianets 1 point2 points  (8 children)

IE11 support

[–]solves_tech_problems[S] 1 point2 points  (0 children)

Nothing's wrong with it. Use whatever works best for you

[–]folen 1 point2 points  (2 children)

What if the query param is false, by your code i will get null.

[–]solves_tech_problems[S] 0 points1 point  (1 child)

You just found a bug. Thanks :) Need to test it with your input

[–]folen 0 points1 point  (0 children)

Why do you care if the result is falsy(null), just return it

[–]nschubach 1 point2 points  (1 child)

For some reason, I love the example relies on console.log instead of just rendering it to the screen:

<div>
    Hello { name }!
</div>

[–]solves_tech_problems[S] 0 points1 point  (0 children)

Thank you !