Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
The state needs to be up-to-date with the query too, and this can be done with listening to asPath( I'm not sure about this solution's performance, if you have better one, comment meπ ).
I always struggled with such problems, and I made a package from one of them once, So If you wanted to make a npm package from this idea, no problem, I'll be the first one to use it.
In useState we pass a callback, It's called lazy initialization, and it's a perfect thing for performance. Query-string package is so useful, we use it to parse the asPath string, But if you don't like to use foreign libraries, you can implement your algorithm. If we pass our initial query to the hook, it will be mixed with the url-based initial query, then we set the query in the url. So: