🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

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

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

React query params hooks

0.9.0
latest
Source
npm
Version published
Weekly downloads
1
-50%
Maintainers
2
Weekly downloads
 
Created
Source

React Query Params Hooks

NPM npm bundle size npm type definitions NPM npm GitHub stars

Easy query params handling for React

  • Better Typed

Features

  • :rocket: Simple, fast and light
  • :factory: 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>
  );
};

Keywords

react

FAQs

Package last updated on 30 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts