New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ericlathrop/react-query-string-router

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ericlathrop/react-query-string-router

Mini router for query string parameters

  • 0.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Query String Router

A mini router for reading/writing query string parameters in your components. Adds new entries to the browser history when parameters are set. Uses React's context and hooks.

Example

Try the demo by running npm start in the demo folder.

import React, { useContext } from 'react';
import { QueryStringRouterContext, QueryStringRouterProvider } from "@ericlathrop/react-query-string-router";

function App() {
  return (
    <QueryStringRouterProvider>
        <Counter />
    </QueryStringRouterProvider>
  );
}

export function Counter() {
  const { params, setAllParams } = useContext(QueryStringRouterContext);
  const counter = parseInt(params.counter) || 0;

  return (
    <div>
      <div>
        Counter is {counter}
      </div>
      <div>
        <button onClick={() => setAllParams({ counter: counter + 1 })}>
          Increment counter
        </button>
      </div>
    </div>
  );
}

API

QueryStringRouterContext

A normal React Context object.

Use with the useContext hook like this:

  const { params, setAllParams } = useContext(QueryStringRouterContext);

The context contains 2 keys: params and setAllParams.

params

The page's query string parameters as a JavaScript object.

setAllParams(newParams)

A function that updates all query string parameters in the URL, and adds a new entry to the browser history. Exclude a key from newParams to remove it from the URL.

QueryStringRouterProvider

A normal React Context.Provider object. Wrap this around the top-level of your app to make the query string parameters available everywhere.

Keywords

FAQs

Package last updated on 23 Jul 2020

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