Socket
Book a DemoInstallSign in
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
npmnpm
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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.