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

@imjakechapman/use-query-params

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@imjakechapman/use-query-params

React hook to easily read and manipulate query params

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

use-query-params

React hook to easily read and manipulate query params

Install

yarn add @imjakechapman/use-query-params
npm install @imjakechapman/use-query-params

Usage (TypeScript)

import React, { useState } from 'react';
import { useQueryParams } from 'use-query-params';

// Types of all your query parameters
type QueryParams = {
  search?: string;
  options?: string[];
  map?: {
    [key: string]: any;
  },
};

// Your default parameters
const defaultParams: QueryParams = {
  search: 'immadefaultparam',
  options: ['well', 'so', 'am', 'i', '!'],
  map: {
    dont: [
      "forget",
      "about",
      "me",
    ],
  },
};

const App: React.FC = () => {
  const { queryParams, updateQueryParams } = useQueryParams<QueryParams>(defaultParams);

  function updateSomeParam() {
    updateQueryParams({
      ...queryParams,
      search: "immaNewValue",
    });
  }

  return (
    <h1>Enjoy your params</h1>
    <pre>
      {JSON.stringify(queryParams, null, 2)}
    </pre>
  )
}

export default App;

License

MIT © imjakechapman


This hook is created using create-react-hook.

FAQs

Package last updated on 17 Dec 2019

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