Closed louis-sanna-eki closed 3 years ago
Hi, thank you for using the library and sharing with me your concern!
First, you can open the Flow.drawio
file with diagrams.net - Draw.io, to see when we assigning the default values into the returned object.
I don't remember exactly the decisions I made. Let's think.
options
object to enable showing the default values?useEffect
to set the value when the component is mounted? (I'm asking to understand the use-case).@baruchiro
Thanks for having taken the time to look at this issue.
(I'm leaving the issue open, but don't hesitate to close if you want)
OK then, thanks @louis-sanna-eki for your suggestion. I understand it, but I chose to take the another approach, which is also logical, so I will not change it for now.
Thanks again, and feel free to open other issues!
Use case
I would like to uniquely sync the state with the URL (modulo param permutation). This is not the case when using default, the same state can lead to two distinct url.
Current behavior
For instance on demo page (https://github.com/baruchiro/use-route-as-state),
const [foo, setFoo] = useQueryStringKey('foo', 'bar')
, the default value offoo
(bar
) does not show up in the URL on page load. Then after manual update is does.First page load:
After changing the
foo
in input and setting it back tobar
.Any reco on how to make sure the URL is
https://baruchiro.github.io/use-route-as-state/?foo=bar
on page load?