Comments (2)
Hi and thank you for the very well written issue. Sorry for the delay in my response!
My current take is this can be solved in userland via hooks/context.
For instance I have a useGlobalFilters
hook that just wraps the useQueryParams
for a few parameters that are used on each page. I would expect in this case they are deserializing to different instances each time but it hasn't been an issue for me.
The alternative is to create an AppQueryParamsContext
or something and a useAppQueryParams()
hook that reads from it. e.g.
import * as React from 'react';
import { useQueryParams } from 'use-query-params';
const AppQueryParamContext = React.createContext(undefined);
export function AppQueryParamProvider({ children }) {
/* [query, setQuery] */
const contextValue = useQueryParams({ foo: StringParam, bar: NumberParam });
return (
<AppQueryParamContext.Provider value={contextValue}>
{children}
</AppQueryParamContext.Provider>
);
}
export function useAppQueryParams() {
return React.useContext(AppQueryParamContext);
}
Note I haven't tested this context approach, I'm not sure if it results in a render happening between param updates and the context updating, but it should work.
from use-query-params.
Hi there, happy to say this has been added in v2.0.0-rc.0 via the params
option. See the changelog for details.
from use-query-params.
Related Issues (20)
- removeDefaultsFromUrl: true doesn't take equals into account HOT 2
- Missing exports for encode/decodeDateTime
- Unable to disable scroll to top HOT 3
- includeAllParams not working HOT 2
- Typescript warning in serialize-query-params for createEnumArrayParam (when following readme )
- feature request: export removeDefaults for end users, or add an option to encodeQueryParams
- Uncaught TypeError: Cannot destructure property 'navigator' of '(0 , import_react.useContext)(...)' as it is null. HOT 11
- Add `use client` directive HOT 2
- Empty string array value not parsed correctly HOT 1
- Peer dependencies in version 2.2.1 HOT 2
- Error using use-query-params when running build with Astro and Netlify HOT 4
- [Question] is there way to use ArrayParam along with ObjectParam?
- Query parameters decorator
- two `setParam()` calls made together overwrite each other HOT 1
- Maintenance
- Request: Add option to store array params as comma-separated list HOT 1
- Race conditions while using react-router-6 adapter HOT 4
- Logs meant for development showing up in production
- Force re-renders
- Links to examples in npm version of the docs are dead
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-query-params.