Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-query-params

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-query-params

React Hook for managing state in URL query parameters with easy serialization.

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
299K
increased by5.88%
Maintainers
1
Weekly downloads
 
Created

What is use-query-params?

The `use-query-params` package is a React hook for managing URL query parameters in a declarative way. It simplifies the process of reading and updating query parameters in the URL, making it easier to manage state that is reflected in the URL.

What are use-query-params's main functionalities?

Reading Query Parameters

This feature allows you to read query parameters from the URL. In this example, the `search` query parameter is read and displayed in the component.

import { useQueryParam, StringParam } from 'use-query-params';

function MyComponent() {
  const [search, setSearch] = useQueryParam('search', StringParam);
  return <div>Search: {search}</div>;
}

Updating Query Parameters

This feature allows you to update query parameters in the URL. In this example, the `search` query parameter is updated based on the input field's value.

import { useQueryParam, StringParam } from 'use-query-params';

function MyComponent() {
  const [search, setSearch] = useQueryParam('search', StringParam);
  return (
    <div>
      <input value={search || ''} onChange={e => setSearch(e.target.value)} />
    </div>
  );
}

Handling Multiple Query Parameters

This feature allows you to handle multiple query parameters simultaneously. In this example, both `search` and `page` query parameters are managed and updated.

import { useQueryParams, StringParam, NumberParam } from 'use-query-params';

function MyComponent() {
  const [query, setQuery] = useQueryParams({ search: StringParam, page: NumberParam });
  return (
    <div>
      <input value={query.search || ''} onChange={e => setQuery({ search: e.target.value })} />
      <button onClick={() => setQuery({ page: (query.page || 0) + 1 })}>Next Page</button>
    </div>
  );
}

Other packages similar to use-query-params

Keywords

FAQs

Package last updated on 24 Mar 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc