GithubHelp home page GithubHelp logo

Comments (2)

pbeshai avatar pbeshai commented on August 21, 2024

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.

pbeshai avatar pbeshai commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.