npm.io
0.1.3 • Published 4 years ago

next-jotai-sync-location

Licence
MIT
Version
0.1.3
Deps
0
Size
9 kB
Vulns
0
Weekly
0
Stars
7

Sync jotai atoms with Next.js router

Why?

As dai-shi mentioned, there is no easy way to keep atoms in sync with window.location or the various available routers, so i wrote a simple wrapper over atomWithStorage.

Install

yarn add next-jotai-sync-location

or

npm install next-jotai-sync-location

How to use

Method has the same signature as atomWithHash, but you can't provide a subscription callback.

import atomWithLocation from "next-jotai-sync-location"

const countAtom = atomWithLocation("count", 0)
const countAtomWithReplace = atomWithLocation("count", 0, {
  replaceState: true
})
const countAtomWithoutDelay = atomWithLocation("count", 0, { delayInit: false })

Keywords