gatsby-plugin-use-query-params

1.0.1 • Public • Published

gatsby-plugin-use-query-params

Drop in support for use-query-params

Table of Contents

Installation

npm install use-query-params gatsby-plugin-use-query-params

Usage

1. Register plugin

In gatsby-config.js:

module.exports = {
  plugins: [
    ...otherPlugins,
 
    "gatsby-plugin-use-query-params",
  ],
};

2. Use use-query-params package as usual. Here is its documentation.

import React from "react";
import { useQueryParam, NumberParam, StringParam } from "use-query-params";
 
const UseQueryParamExample = () => {
  // something like: ?x=123&foo=bar in the URL
  const [num, setNum] = useQueryParam("x", NumberParam);
  const [foo, setFoo] = useQueryParam("foo", StringParam);
 
  return (
    <div>
      <h1>num is {num}</h1>
      <button onClick={() => setNum(Math.random())}>Change</button>
      <h1>foo is {foo}</h1>
      <button onClick={() => setFoo(`str${Math.random()}`)}>Change</button>
    </div>
  );
};
 
export default UseQueryParamExample;

License

MIT

Package Sidebar

Install

npm i gatsby-plugin-use-query-params

Weekly Downloads

8,168

Version

1.0.1

License

MIT

Unpacked Size

2.71 kB

Total Files

6

Last publish

Collaborators

  • alexluong