Is there a way to use jotai synced with NextJs router?
See original GitHub issueAt first let me thank you for your awsome store management,
There is a point, storing some data (state) on the query field of the URL is necessary some times,
But I don’t like to handle this directly, I think syncing store with the URL will be a good idea.
In this situation we will have for example a NextRouterAtom
which is connected to the URL and changing query or state will cause changing the other one.
What is your idea about that?
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (8 by maintainers)
Top Results From Across the Web
Next.js — Jotai, primitive and flexible state management for ...
Jotai has support for hydration of atoms with useHydrateAtoms . The documentation for the hook can be seen here. Sync with router. It's...
Read more >Up & Running with Jotai, Typescript and NextJS
Simple, elegant state management with Jotai and type-safety with Typescript. Today we will learn how to use them together.
Read more >next-jotai-sync-location - npm package - Snyk
Sync jotai atoms with Next. As dai-shi mentioned, there is no easy way to keep atoms in sync with window. location or the...
Read more >Next.js and Jotai: Share state across pages | by Markus Tripp
You can use React's Context to pass data through the component tree. Or choose one of the many state managers available. In this...
Read more >/docs/guides/nextjs.mdx | jotai@v1.7.2 | Deno
---title: Next.jsdescription: How to use Jotai with Next.jsnav: 3.04--- ## Hydration ... It's possible to sync Jotai with the router.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure I will work on that, Just let me to read the existing packages which are for connecting router to the Redux and other store managements to see how they work exactly, I will inform you soon.
Well i put together a version that work for get and set. But i know Jotai since yesterday so i took some shortcut and my implementation might be very very bad 😦
I pass the router as an argument to avoid adding a dependency to utils
some shortcuts:
I assume value is string but could be a string array. Need to check the type and act accordingly (in get and set)=> strongly types to either String or String[]Not sure why my value was not initialized without route change so i added aThat’s what delayInit is for! removed the option and set it to true has Router is delayedcallback()
in theconst subscribe