### Development: Run Example App
Source: https://github.com/pbeshai/use-query-params/blob/master/packages/use-query-params/README.md
To run an example application, link the local package, install dependencies in the example directory, and start the app.
```bash
npm link
cd examples/react-router
npm install
npm link use-query-params
npm start
```
--------------------------------
### Run a Specific Example
Source: https://github.com/pbeshai/use-query-params/blob/master/README.md
Starts a specific example application within the monorepo.
```bash
lerna run --scope react-router-example start
```
--------------------------------
### Set Up Example Packages
Source: https://github.com/pbeshai/use-query-params/blob/master/README.md
Bootstraps and links example packages within the monorepo for local development.
```bash
lerna bootstrap --scope "*-example"
lerna link
```
--------------------------------
### Install serialize-query-params
Source: https://github.com/pbeshai/use-query-params/blob/master/packages/serialize-query-params/README.md
Install the library using npm. This is the initial step before using its functionalities.
```bash
npm install --save serialize-query-params
```
--------------------------------
### Install use-query-params
Source: https://github.com/pbeshai/use-query-params/blob/master/packages/use-query-params/README.md
Install the use-query-params package using npm.
```bash
npm install --save use-query-params
```
--------------------------------
### Start Create React App
Source: https://github.com/pbeshai/use-query-params/blob/master/examples/react-router-5/README.md
Runs the Create React App development server. Open http://localhost:3000 to view the app.
```bash
npm start
```
--------------------------------
### Install and Bootstrap Monorepo Dependencies
Source: https://github.com/pbeshai/use-query-params/blob/master/README.md
Installs project dependencies, bootstraps specific packages within the monorepo, builds the project, and runs tests.
```bash
npm install
npx lerna bootstrap --hoist --scope "use-query-params" --scope "serialize-query-params"
npm build
npm test
```
--------------------------------
### Basic useQueryParams Example
Source: https://github.com/pbeshai/use-query-params/blob/master/packages/use-query-params/README.md
Demonstrates reading multiple query parameters ('foo' and 'bar') using a configuration object and updating them. Shows setting specific parameters, multiple parameters, and functional updates.
```javascript
import { useQueryParams, StringParam, NumberParam } from 'use-query-params';
// reads query parameters `foo` and `bar` from the URL and stores their decoded values
const [query, setQuery] = useQueryParams({ foo: NumberParam, bar: StringParam });
setQuery({ foo: 500 })
setQuery({ foo: 123, bar: 'zzz' }, 'push');
// to unset or remove a parameter set it to undefined and use pushIn or replaceIn update types
setQuery({ foo: undefined }) // ?foo=123&bar=zzz becomes ?bar=zzz
// functional updates are also supported:
setQuery((latestQuery) => ({ foo: latestQuery.foo + 150 }))
```
--------------------------------
### Basic useQueryParam Example
Source: https://github.com/pbeshai/use-query-params/blob/master/packages/use-query-params/README.md
Demonstrates reading a numeric query parameter 'foo' and updating it. Shows how to set a value and how to unset it by passing undefined. Supports functional updates.
```javascript
import { useQueryParam, NumberParam } from 'use-query-params';
// reads query parameter `foo` from the URL and stores its decoded numeric value
const [foo, setFoo] = useQueryParam('foo', NumberParam);
setFoo(500);
setFoo(123, 'push');
// to unset or remove a parameter set it to undefined and use pushIn or replaceIn update types
setFoo(undefined) // ?foo=123&bar=zzz becomes ?bar=zzz
// functional updates are also supported:
setFoo((latestFoo) => latestFoo + 150)
```
--------------------------------
### React Router 6 Adapter Setup
Source: https://github.com/pbeshai/use-query-params/blob/master/packages/use-query-params/README.md
Set up the QueryParamProvider with the React Router 6 adapter for integrating with React Router 6.
```javascript
import React from 'react';
import ReactDOM from 'react-dom/client';
import { QueryParamProvider } from 'use-query-params';
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import App from './App';
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
): React.FC ):
React.FC