@better-typed/react-query-params-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

React Query Params Hooks

NPM npm bundle size npm type definitions NPM npm GitHub stars

Easy query params handling for React

Features

  • 🚀 Simple, fast and light
  • 🏭 Set, Update, Delete, Clear
  • 🪗 Provider for global configs and any environment

Install

npm install --save @better-typed/react-query-params-hooks

or

yarn add @better-typed/react-query-params-hooks

Usage

import React from "react";
import { useQueryParams } from "@better-typed/react-query-params-hooks";

const MyComponent: React.FC = () => {
  const {queryParams, queryString, stringify, setQueryParam, setQueryParams, updateQueryParams, deleteQueryParam, clearQueryParams } = useQueryParams()

  return (
    // ...
  )
}

Connect to your router

First we have to wrap our App with QueryParamsProvider and provide setQueryParams and getQueryString methods. Below we have an example of usage with React Router v6.

import React from "react";
import { useQueryParams } from "@better-typed/react-query-params-hooks";

const App: React.FC = ({ children }) => {
  const location = useLocation();
  const [, setSearchParams] = useSearchParams();

  return (
    <QueryParamsProvider
      getQueryString={() => location.search}
      setQueryParams={(search) => setSearchParams({ search }, { replace: true })}
    >
      {children}
    </QueryParamsProvider>
  );
};

/@better-typed/react-query-params-hooks/

    Package Sidebar

    Install

    npm i @better-typed/react-query-params-hooks

    Weekly Downloads

    1

    Version

    0.9.0

    License

    MIT

    Unpacked Size

    38.5 kB

    Total Files

    11

    Last publish

    Collaborators

    • geras_nyx
    • albelew
    • prc5