JSPM

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

0.9.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q33905F
  • License MIT

React query params hooks

Package Exports

  • @better-typed/react-query-params-hooks
  • @better-typed/react-query-params-hooks/dist/index.cjs.js
  • @better-typed/react-query-params-hooks/dist/index.esm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@better-typed/react-query-params-hooks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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>
  );
};