Releases: xiel/use-location-state
Releases · xiel/use-location-state
v3.1.2 - Batching Fixes
Full Changelog: v3.1.1...v3.1.2
Support for Next.js
What's Changed
- feat: Support Next.js by @xiel in #419 (fixes #414)
- fix: Upgrade node to v18 by @xiel in #417
- chore: Updated dependencies
Next.js Support
Import from use-location-state/next
to use the router build into Next.js, which enables you to use the query state also during SSR.
import { useQueryState } from 'use-location-state/next'
export { getServerSideProps } from 'use-location-state/next' // [1]
export default function Page() {
const [count, setCount] = useQueryState('count', 0)
//...
}
[1] Page must be server rendered (SRR), otherwise React warns about a hydration mismatch, when your initial rendering depends on the query state. Export your own getServerSideProps
function or the provided empty one.
Full Changelog: v3.0.1...v3.1.1
Support react-router v6
- Add Support for react-router v6
- API stayed the same, you just need to upgrade to the new major version of react-router (^6.0.0)
- Thanks to @gitter-me for opening the issue (#230)
- Checkout their fancy new docs: https://reactrouter.com
Full Changelog: v2.5.0...v3.0.0
Reset using null
- you can now reset the query string and receive the defaultValue by calling the setter with null
const [name, setName] = useQueryState('name', 'Sarah')
// eg. in some click callback
setName('Felix')
// ... later you want to reset back to the default value, you can just call
setName(null)
useQueryReducer + useLocationReducer
- lets you control a query/location state using a reducer, dispatch and actions
- currently available on the next tag
vanilla
yarn add use-location-state@next
react-router
yarn add react-router-use-location-state@next
SSR bugfix 🐛
- fixes a bug where (SSR) build with gatsby / node would crash due to missing btoa thx @bitttttten (#94)
useLocationState()
useLocationState(name, defaultValue)
was added 🎉- restores the latest value after navigation actions (back/forward), by keeping value in
history.state
- supported value types:
string | number | boolean | Date | Array | Object
- handles complex & nested values - all values that can be serialized are supported
- restores the latest value after navigation actions (back/forward), by keeping value in
v2.2.0
- method option (push/replace) in set function is now also supported for hash query strings
const [value, setValue] = useQueryState('itemName', 'default value')
<button onClick={() => setValue('a pushed value', { method: 'push' })}>...</button>
- fix: stale state after change in other component #79
v1.0.2
Bug Fixes
- package: update @types/node to version 11.13.7 (0973706)
- package: update react-scripts to version 3.0.0 (c80d054)
- Detached git HEAD (98c5715)
- lerna version remove beta preid (did not work anyway) (6c05f3d)
Features
- use-location-state: add useLocationHashQueryStringInterface hook (4d61250)
- use-location-state: add useLocationHashQueryStringInterface hook (0ca3601)
- useLocationHashQueryState: provide new exports useLocationHashQueryState and useLocationHashQu (666aa4a), closes #20
BREAKING CHANGES
- useLocationHashQueryState: renamed exports, queryState and setQueryState are now all returned as array tuples
v1.0.0
Bug Fixes
- package: update @types/node to version 11.13.7 (0973706)
- package: update react-scripts to version 3.0.0 (c80d054)
- Detached git HEAD (98c5715)
- lerna version remove beta preid (did not work anyway) (6c05f3d)
Features
- use-location-state: add useLocationHashQueryStringInterface hook (4d61250)
- use-location-state: add useLocationHashQueryStringInterface hook (0ca3601)
- useLocationHashQueryState: provide new exports useLocationHashQueryState and useLocationHashQu (666aa4a), closes #20
BREAKING CHANGES
- useLocationHashQueryState: renamed exports, queryState and setQueryState are now all returned as array tuples