Gathering detailed insights and metrics for recoil-sync-next
Gathering detailed insights and metrics for recoil-sync-next
Gathering detailed insights and metrics for recoil-sync-next
Gathering detailed insights and metrics for recoil-sync-next
recoil-sync
recoil-sync provides an add-on library to help synchronize Recoil state with external systems
recoil
Recoil - A state management library for React
recoil-persist
Package for recoil to persist and rehydrate store
flux
An application architecture based on a unidirectional data flow
npm install recoil-sync-next
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
59 Stars
924 Commits
8 Forks
15 Watching
5 Branches
10 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
2.9%
178
Compared to previous day
Last week
20.1%
937
Compared to previous week
Last month
-7.4%
3,992
Compared to previous month
Last year
-21.6%
46,508
Compared to previous year
7
32
Recoil Sync stores for Next.js
The new router for the app/
directory introduced by Next.js 13 is not yet supported.
1npm install recoil recoil-sync recoil-sync-next 2# or 3yarn add recoil recoil-sync recoil-sync-next 4# or 5pnpm add recoil recoil-sync recoil-sync-next
This provides recoil-sync's URL Persistence functionality interfaced with next/router.
<RecoilURLSyncJSON>
and <RecoilURLSyncTransit>
always use
shallow routing
to update the browser URL.
When the URL has changed, they cause re-rendering of themselves.
Therefore, you should concider to use React.memo()
for Page components that use URL synced atoms (
example
).
A version of <RecoilURLSyncJSON> that works with next/router to sync atoms with the browser URL using JSON encoding. This should be a child element of <RecoilRoot>.
1function RecoilURLSyncJSONNext(props: { 2 storeKey?: string | undefined 3 location: LocationOption 4 children: ReactNode 5}): ReactNode
storeKey
location
children
1import { RecoilURLSyncJSONNext } from 'recoil-sync-next' 2 3function MyApp({ Component, pageProps }: AppProps) { 4 return ( 5 <RecoilRoot> 6 <RecoilURLSyncJSONNext location={{ part: 'queryParams' }}> 7 <Component {...pageProps} /> 8 </RecoilURLSyncJSONNext> 9 </RecoilRoot> 10 ) 11}
A version of <RecoilURLSyncTransit> that works with next/router to sync atoms with the browser URL using Transit encoding. This should be a child element of <RecoilRoot>.
1function RecoilURLSyncTransitNext(props: { 2 storeKey?: string | undefined 3 location: LocationOption 4 handlers?: ReadonlyArray<TransitHandler<any, any>> 5 children: ReactNode 6}): ReactNode
storeKey
location
handlers
children
1import { RecoilURLSyncTransitNext } from 'recoil-sync-next' 2 3function MyApp({ Component, pageProps }: AppProps) { 4 return ( 5 <RecoilRoot> 6 <RecoilURLSyncTransitNext location={{ part: 'queryParams' }}> 7 <Component {...pageProps} /> 8 </RecoilURLSyncTransitNext> 9 </RecoilRoot> 10 ) 11}
A version of <RecoilURLSync> that works with next/router to sync atoms with the browser URL using your own serialize/deserialize algorithms. This should be a child element of <RecoilRoot>.
1function RecoilURLSyncNext(props: { 2 storeKey?: string | undefined 3 location: LocationOption 4 serialize: (data: unknown) => string 5 deserialize: (str: string) => unknown 6 children: ReactNode 7}): ReactNode
storeKey
location
serialize
deserialize
children
1import { RecoilURLSyncNext } from 'recoil-sync-next' 2import qs from 'qs' 3 4function MyApp({ Component, pageProps }: AppProps) { 5 return ( 6 <RecoilRoot> 7 <RecoilURLSyncNext 8 location={{ part: 'queryParams' }} 9 serialize={qs.stringify} 10 deserialize={qs.parse} 11 > 12 <Component {...pageProps} /> 13 </RecoilURLSyncNext> 14 </RecoilRoot> 15 ) 16}
Provides persistence of atoms to session storage synced with the position of the history entry.
It will save atoms to session storage when the history entry's position is moved.
When the user moves backward/forward on history entries (i.e. 'popstate'
event is fired),
the atoms saved with that position is restored.
To sync atoms with the position of the history entry using JSON encoding. This should be a child element of <RecoilRoot>.
1function RecoilHistorySyncJSONNext(props: { 2 storeKey?: string | undefined 3 children: ReactNode 4}): ReactNode
storeKey
children
1import { RecoilHistorySyncJSONNext } from 'recoil-sync-next' 2 3function MyApp({ Component, pageProps }: AppProps) { 4 return ( 5 <RecoilRoot> 6 <RecoilHistorySyncJSONNext> 7 <Component {...pageProps} /> 8 </RecoilHistorySyncJSONNext> 9 </RecoilRoot> 10 ) 11}
To sync atoms with the position of the history entry using Transit encoding. This should be a child element of <RecoilRoot>.
1function RecoilHistorySyncTransitNext(props: { 2 storeKey?: string | undefined 3 handlers?: ReadonlyArray<TransitHandler<any, any>> 4 children: ReactNode 5}): ReactNode
storeKey
handlers
children
1import { RecoilHistorySyncTransitNext } from 'recoil-sync-next' 2 3function MyApp({ Component, pageProps }: AppProps) { 4 return ( 5 <RecoilRoot> 6 <RecoilHistorySyncTransitNext> 7 <Component {...pageProps} /> 8 </RecoilHistorySyncTransitNext> 9 </RecoilRoot> 10 ) 11}
atom
, but initial value can be specified when using it.
Note: This is just a utility and does not depend on either Recoil Sync or Next.js.
1function initializableAtom<T extends SerializableParam>(options: { 2 key: string 3 effects?: 4 | ReadonlyArray<AtomEffect<T>> 5 | ((param: P) => ReadonlyArray<AtomEffect<T>>) 6 dangerouslyAllowMutability?: boolean 7}): (initialValue: T) => RecoilState<T>
See atom for more info.
A function which takes its initialValue
.
1import { initializableAtom } from 'recoil-sync-next' 2 3const countState = initializableAtom<number>({ 4 key: 'count', 5}) 6 7const MyComponent: React.FC = () => { 8 const [count, setCount] = useRecoilState(countState(100)) // count is initialized to 100 9 ... 10}
atomFamily
, but initial value can be specified individually when using it.
Note: This is just a utility and does not depend on either Recoil Sync or Next.js.
1function initializableAtomFamily< 2 T extends SerializableParam, 3 P extends SerializableParam 4>(options: { 5 key: string 6 effects?: 7 | ReadonlyArray<AtomEffect<T>> 8 | ((param: P) => ReadonlyArray<AtomEffect<T>>) 9 dangerouslyAllowMutability?: boolean 10}): (parameter: P, initialValue: T) => RecoilState<T>
See atomFamily for more info.
A function which takes parameter
that map to an atom, and its initialValue
.
1import { initializableAtomFamily } from 'recoil-sync-next' 2 3const countState = initializableAtomFamily<number, string>({ 4 key: 'count', 5}) 6 7const MyComponent: React.FC = () => { 8 const [count1, setCount1] = useRecoilState(countState('foo', 0)) // count1 is initialized to 0 9 const [count2, setCount2] = useRecoilState(countState('bar', 100)) // count2 is initialized to 100 10 ... 11}
No vulnerabilities found.
No security vulnerabilities found.