use-route-as-state
Use React Router route and query string as component state
Install
npm install --save use-route-as-state
Usage
You can see a live demo, including code, here.
// URL: /:param?query=
import * as React from 'react'
import { useRouteParams, useQueryParams } from 'use-route-as-state'
const Example = () => {
const [{ param }, setRouteParams] = useRouteParams()
const [{ query }, setQueryParams] = useQueryParams()
return (
<div>
<input
value={ param }
onChange={({ target }) => setRouteParams({ param: target.value })} />
<input
value={ query }
onChange={({ target }) => setQueryParams({ query: target.value })} />
</div>
)
}
API
This library is trying to…