use-query-string
use-query-string copied to clipboard
Limitation
In practice, I have found that I cannot use useQueryString inside multiple hooks. The updates are done in such a way that the updates conflict with each other. Normally, the setter returned from a hook has a variant with is a callback where it passes you the current value and you override that. The useQueryString result indeed includes such a variation, but the data it passes in appears to be out of date.
My solution was to use useQueryString in exactly one place and then pass the return value down into other hooks in order for them all to share a single instance of QueryStringResult. That appears to work although it isn't obvious this is necessary. Or perhaps I missed something in the documentation.