gatsby-plugin-use-query-params
v1.0.1
Published
Drop in support for [`use-query-params`](https://www.npmjs.com/package/use-query-params)
Downloads
49,169
Maintainers
Readme
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