Recoil Sync stores for Next.js

Overview

recoil-sync-next

Recoil Sync stores for Next.js

Features

Installation

npm install recoil recoil-sync recoil-sync-next
# or
yarn add recoil recoil-sync recoil-sync-next
# or
pnpm add recoil recoil-sync recoil-sync-next

URL Persistence

This provides recoil-sync's URL Persistence functionality interfaced with next/router.

A version of that works with next/router to sync atoms with the browser URL using JSON encoding. This should be a child element of .

function RecoilURLSyncJSONNext(props: {
  storeKey?: string | undefined
  location: LocationOption
  children: ReactNode
}): ReactNode

Props

  • storeKey
  • location
    • Tis prop specifies what part of the URL to sync. See URL Location for more info.
  • children
    • React elements in your component tree.

Example

import { RecoilURLSyncJSONNext } from 'recoil-sync-next'

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <RecoilRoot>
      <RecoilURLSyncJSONNext location={{ part: 'queryParams' }}>
        <Component {...pageProps} />
      </RecoilURLSyncJSONNext>
    </RecoilRoot>
  )
}

A version of that works with next/router to sync atoms with the browser URL using Transit encoding. This should be a child element of .

function RecoilURLSyncTransitNext(props: {
  storeKey?: string | undefined
  location: LocationOption
  handlers?: ReadonlyArray<TransitHandler<any, any>>
  children: ReactNode
}): ReactNode

Props

  • storeKey
  • location
    • Tis prop specifies what part of the URL to sync. See URL Location for more info.
  • handlers
    • The array of user defined custom encoder/decoder object. See Custom Classes for more info.
  • children
    • React elements in your component tree.

Example

import { RecoilURLSyncTransitNext } from 'recoil-sync-next'

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <RecoilRoot>
      <RecoilURLSyncTransitNext location={{ part: 'queryParams' }}>
        <Component {...pageProps} />
      </RecoilURLSyncTransitNext>
    </RecoilRoot>
  )
}

Session Storage Persistence Synced with History

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 .

function RecoilHistorySyncJSONNext(props: {
  storeKey?: string | undefined
  children: ReactNode
}): ReactNode

Props

  • storeKey
  • children
    • React elements in your component tree.

Example

import { RecoilHistorySyncJSONNext } from 'recoil-sync-next'

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <RecoilRoot>
      <RecoilHistorySyncJSONNext>
        <Component {...pageProps} />
      </RecoilHistorySyncJSONNext>
    </RecoilRoot>
  )
}

To sync atoms with the position of the history entry using Transit encoding. This should be a child element of .

function RecoilHistorySyncTransitNext(props: {
  storeKey?: string | undefined
  handlers?: ReadonlyArray<TransitHandler<any, any>>
  children: ReactNode
}): ReactNode

Props

  • storeKey
  • handlers
    • The array of user defined custom encoder/decoder object. See Custom Classes for more info.
  • children
    • React elements in your component tree.

Example

import { RecoilHistorySyncTransitNext } from 'recoil-sync-next'

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <RecoilRoot>
      <RecoilHistorySyncTransitNext>
        <Component {...pageProps} />
      </RecoilHistorySyncTransitNext>
    </RecoilRoot>
  )
}

Utilities

atomFamilyWithInitialValue

atomFamily, but initial value can be specified individually.

function atomFamilyWithInitialValue<
  T extends SerializableParam,
  P extends SerializableParam
>(options: {
  key: string
  effects?:
    | ReadonlyArray<AtomEffect<T>>
    | ((param: P) => ReadonlyArray<AtomEffect<T>>)
  dangerouslyAllowMutability?: boolean
}): (parameter: P, initialValue: T) => RecoilState<T>

Type Parameters

  • T
    • The type of the atom value. It must be compared using value-equality and must be serializable.
  • P
    • The type of the paramter that map to each atom. It must be compared using value-equality and must be serializable.

Parameters

See atomFamily for more info.

Return

A function which takes paramter that map to an atom, and its initialValue.

Example

import { atomFamilyWithInitialValue } from 'recoil-sync-next'

const countState = atomFamilyWithInitialValue<number, string>({
  key: 'count',
})

const MyComponent: React.FC = () => {
  const [count1, setCount1] = useRecoilState(countState('foo', 0))   // count1 is initialized to 0
  const [count2, setCount2] = useRecoilState(countState('bar', 100)) // count2 is initialized to 100
  ...
}
Comments
  • Refreshing of the page when navigating thru the history

    Refreshing of the page when navigating thru the history

    Hi there, firstly thanks for the nice plugin, it's exactly what I am looking for :) When there new state in the url and for example I want to go back, the whole pages reloads, which is not very good ux and it's unnecessary really.

    When I was manipulating query by myself, I didn't have the issue, I was changing the url as this: router.push({ query: { ...router.query, param: 'value' }, }); Would it be possible to rewrite like this in the library so the unnecessary reload is not there? Thanks!

    opened by Daidalos117 4
  • Examples of react hook form

    Examples of react hook form

    I wanted a performance-optimized implementation, but could not come up with a way to control the number of times rendering was called. I have tried the following.

    • With snapshot -> Rendering call increases.
    • Controlling by defaultValue of terminal component -> increases drawing.

    If there is a better way, I need advice.

    opened by AkifumiSato 2
  • Update typescript-eslint monorepo to v5.30.6

    Update typescript-eslint monorepo to v5.30.6

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @typescript-eslint/eslint-plugin | 5.30.5 -> 5.30.6 | age | adoption | passing | confidence | | @typescript-eslint/parser | 5.30.5 -> 5.30.6 | age | adoption | passing | confidence |


    Release Notes

    typescript-eslint/typescript-eslint (@​typescript-eslint/eslint-plugin)

    v5.30.6

    Compare Source

    Note: Version bump only for package @​typescript-eslint/eslint-plugin

    typescript-eslint/typescript-eslint (@​typescript-eslint/parser)

    v5.30.6

    Compare Source

    Note: Version bump only for package @​typescript-eslint/parser


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about these updates again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 2
  • Error: This component must be used inside a <RecoilRoot> component.

    Error: This component must be used inside a component.

    I tried to develop with yarn add link:<local path> and got the following error

    Server Error
    Error: This component must be used inside a <RecoilRoot> component.
    

    It seems to be related to the following issue, but I tried it with reac@17 and [email protected] and got an error. https://github.com/facebookexperimental/Recoil/issues/1802

    opened by AkifumiSato 2
  • Add RecoilURLSyncNext

    Add RecoilURLSyncNext

    Implements a simple exposure of RecoilURLNext following the pattern of other root tags.

    Some people may want to implement their own custom serializer or deserializer based on their application's needs, wrapping RecoilURLSync makes it easier for people with such use cases to use this package.

    P.S - please squash my commit messages

    opened by dyingg 1
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • package.json (npm)

    Configuration

    🔡 Renovate has detected a custom config for this PR. Feel free to ask for help if you have any doubts and would like it reviewed.

    Important: Now that this branch is edited, Renovate can't rebase it from the base branch any more. If you make changes to the base branch that could impact this onboarding PR, please merge them manually.

    What to Expect

    With your current configuration, Renovate will create 1 Pull Request:

    Pin dependencies

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • Update typescript-eslint monorepo to v5.47.1

    Update typescript-eslint monorepo to v5.47.1

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @typescript-eslint/eslint-plugin | 5.47.0 -> 5.47.1 | age | adoption | passing | confidence | | @typescript-eslint/parser | 5.47.0 -> 5.47.1 | age | adoption | passing | confidence |


    Release Notes

    typescript-eslint/typescript-eslint (@​typescript-eslint/eslint-plugin)

    v5.47.1

    Compare Source

    Bug Fixes
    • ast-spec: correct some incorrect ast types (#​6257) (0f3f645)
    • eslint-plugin: [member-ordering] correctly invert optionalityOrder (#​6256) (ccd45d4)
    typescript-eslint/typescript-eslint (@​typescript-eslint/parser)

    v5.47.1

    Compare Source

    Note: Version bump only for package @​typescript-eslint/parser


    Configuration

    📅 Schedule: Branch creation - "after 10pm every weekend,before 5am every weekend" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about these updates again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update dependency @types/node to v18.11.18

    Update dependency @types/node to v18.11.18

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @types/node (source) | 18.11.17 -> 18.11.18 | age | adoption | passing | confidence |


    Configuration

    📅 Schedule: Branch creation - "after 10pm every weekend,before 5am every weekend" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update typescript-eslint monorepo to v5.47.0

    Update typescript-eslint monorepo to v5.47.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @typescript-eslint/eslint-plugin | 5.46.1 -> 5.47.0 | age | adoption | passing | confidence | | @typescript-eslint/parser | 5.46.1 -> 5.47.0 | age | adoption | passing | confidence |


    Release Notes

    typescript-eslint/typescript-eslint (@​typescript-eslint/eslint-plugin)

    v5.47.0

    Compare Source

    Features
    • eslint-plugin: [no-floating-promises] add suggestion fixer to add an 'await' (#​5943) (9e35ef9)

    5.46.1 (2022-12-12)

    Note: Version bump only for package @​typescript-eslint/eslint-plugin

    typescript-eslint/typescript-eslint (@​typescript-eslint/parser)

    v5.47.0

    Compare Source

    Note: Version bump only for package @​typescript-eslint/parser

    5.46.1 (2022-12-12)

    Note: Version bump only for package @​typescript-eslint/parser


    Configuration

    📅 Schedule: Branch creation - "after 10pm every weekend,before 5am every weekend" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about these updates again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update nextjs monorepo to v13.1.1

    Update nextjs monorepo to v13.1.1

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | eslint-config-next | 13.0.7 -> 13.1.1 | age | adoption | passing | confidence | | next (source) | 13.0.7 -> 13.1.1 | age | adoption | passing | confidence |


    Release Notes

    vercel/next.js

    v13.1.1

    Compare Source

    Core Changes
    • Exclude srcset from svg image: #​44308
    • Fix CSS resource path not matched in __entry_css_files__: #​44310
    • Fix next/image 404 when basePath and trailingSlash defined: #​44312
    Documentation Changes
    • Remove experimental for modularizeImports from docs and example: #​44311
    Example Changes
    • Updated dependencies for with-tailwindcss example: #​44289
    Misc Changes
    • Use turbo for packing files in test setup: #​44074
    Credits

    Huge thanks to @​JanKaifer, @​Nutlope, @​styfle, and @​chibicode for helping!

    v13.1.0

    Compare Source

    Core Changes
    • Fix windows slashes for app client entry: #​44052
    • Hash both pitch and main loader for server CSS imports: #​44063
    • Add tracing for testing tools: #​44046
    • Run packing in tests in parallel: #​44048
    • feat: app dir error-global component: #​44066
    • Fix ignoring dev warning for preload component: #​44065
    • refactor(next-swc): introduce next-binding to consolidate dependencies.: #​43473
    • Add lodash to server components external packages: #​44022
    • Fix dev session stopped handling: #​44112
    • Add jsdoc/no-types eslint rule for TypeScript files: #​44049
    • Revert "Remove useState from next/image (#​43587)": #​44094
    • should not contain pages css in app dir: #​44151
    • Upgrade undici to 5.14.0 to fix fetch redirect bug: #​44133
    • build(cargo): fix turbopack + next-swc build: #​43983
    • Align onRecoverableError callback between pages and app dir: #​44161
    • build(cargo): update turbopack: #​44167
    • Update styled-jsx: #​44070
    • Fix crash in GraalVM: #​44176
    • Also check error.message as digest for recoverable errors in pages: #​44185
    • Move options to stable: #​44195
    • Move transpilePackages out of experimental: #​44194
    • Fix CSS resources being duplicated in app dir: #​44168
    • Add telemetry for stable features: #​44201
    • Add warning for experimental flags that have moved: #​44202
    • build(cargo): bump up turbopack: #​44206
    • Bump @vercel/[email protected]: #​44193
    • Disable Image Optimization API when next.config.js has unoptimized: true: #​44205
    • Honour distDir in type generation: #​44207
    • Only once for the next/head usage in app dir: #​44233
    • Enable allowMiddlewareResponseBody by default: #​44224
    • Move modularizeImports out of experimental: #​44240
    • Update config validation for latest turbopack changes: #​44223
    • build(cargo): update turbopack: #​44241
    • update turbopack for bugfixes: #​44251
    Documentation Changes
    • docs: Add explanation about font-display: #​44001
    • Test that adding query can be detected by useSearchParams: #​43969
    • Add static test for useSelectedLayoutSegments: #​43955
    • Docs: Update deployment.md with Firebase, Amplify and Cloudflare: #​44092
    • Add test for rewriting in middleware in app-dir: #​43971
    • docs: Add missing type to import statement: #​44111
    • docs: update next/dynamic docs: #​44067
    • Update disabling-http-keep-alive.md for server-side only: #​43374
    • docs: fix spelling error: #​44191
    • Write tests for navigation between app-dir and pages: #​43881
    • Add docs for middleware flags: #​44235
    Example Changes
    • Updates with-supertokens example: #​44042
    • Fix styled-components setup in turbo example: #​44165
    • update with-turbopack example for postcss/tailwind support: #​44261
    Misc Changes
    • Run packing in tests in parallel
    • Revert "Run packing in tests in parallel"
    • Remove extra turbo test: #​44073
    • Implement new core test API: #​44086
    • Refactor more tests to createNextDescribe: #​44104
    • Add types as a default dependency into tests: #​44140
    • Suggest contributors to use shallow clone: #​44158
    • Update pnpm new-test to use createNextDescribe: #​44147
    • Update README templates to include snippet on next/font: #​44088
    • Wrap CSS variable in var: #​44153
    • Ensure next.url is used instead of next.appPort: #​44163
    • test: add test for notFound during streaming: #​44078
    • Fix test template example: #​44170
    • Remove devcontainer network host argument: #​44157
    • Fix pnpm install on Azure: #​44179
    • Enable ReactRefreshLogBox scss test: #​44180
    • Increase recommended git clone depth: #​44181
    • Document how chain works in BrowserInterface and chain to browser.eval: #​44085
    • Remove browser.refresh in app tests: #​44186
    • Move tests into their test folder: #​44183
    • Add test checking that repeated edits won't cause hydration issues: #​44189
    • Update labeler.json with current next.js team members: #​44231
    Credits

    Huge thanks to @​shuding, @​hanneslund, @​rishabhpoddar, @​JanKaifer, @​huozhi, @​timneutkens, @​kwonoj, @​IamManchanda, @​styfle, @​nyedidikeke, @​jaslong, @​jueungrace, @​longzheng, @​akshitsinha, @​Brooooooklyn, @​gish, and @​sokra for helping!


    Configuration

    📅 Schedule: Branch creation - "after 10pm every weekend,before 5am every weekend" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about these updates again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update dependency @types/react-dom to v18.0.10

    Update dependency @types/react-dom to v18.0.10

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @types/react-dom (source) | 18.0.9 -> 18.0.10 | age | adoption | passing | confidence |


    Configuration

    📅 Schedule: Branch creation - "after 10pm every weekend,before 5am every weekend" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
Releases(v0.0.3)
Owner
Recruit Co., Ltd.
Recruit Co., Ltd.
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Trying 5 Redux Alternatives (Zustand, Recoil, Jotai, Rematch and Redux-Toolkit). Expalined on CoderOne Ytb channel

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Islem Maboud 5 Oct 3, 2022
Google-reviews-crawler - A simple Playwright crawler that stores Google Maps Place/Business reviews to a JSON file.

google-reviews-crawler A simple Playwright crawler that stores Google Maps Place/Business reviews to a JSON file. Usage Clone the repo, install the de

￸A￸l￸e￸x D￸o￸m￸a￸k￸i￸d￸i￸s 6 Oct 26, 2022
A simple single page web-app that stores, removes and edits books' names in the browser's local storage.

A simple single page web-app that stores, removes and edits books' names in the browser's local storage. Made with Webpack bundler

Alejandro Neira 5 Apr 1, 2022
A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

remote-map-cache A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fa

Tomato6966 8 Oct 31, 2022
This Project is basically provides a cloud based solution for the medical stores so they can manage their inventory, expiry, billbook & credits on a single platform

This Project is basically provides a cloud based solution for the medical stores so they can manage their inventory, expiry, billbook & credits on a single platform

Akshay Shivaji Matre 4 Jul 11, 2022
A lightweight abstraction between Svelte stores and Chrome extension storage.

Svelte Chrome Storage A lightweight abstraction between Svelte stores and Chrome extension storage. This library makes data synchronization of backgro

Shaun Wild 10 Nov 15, 2022
A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

form-storage A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again. Installation via npm npm install

appleple 159 Dec 10, 2022
This monorepo stores all code and assets of all projects with which we develop regels.overheid.nl

Welcome Introduction In 2021 Utrecht started developing the Virtual Income Desk with Open Rules. An initiative with the aim for citizens to always and

Ministerie van Binnenlandse Zaken en Koninkrijksrelaties 5 Dec 8, 2022
This is a project that add, stores and deletes current book in the library

Project Name Awesome books: with ES6 Description the project. In this project, I restructured my Awesome books app code. The goal was to make it more

Harrison Njuguna 5 Nov 11, 2022
Automatically sync your leetcode solutions to your github account - top 5 trending GitHub repository

LeetHub - Automatically sync your code to GitHub. Top 5 Trending JavaScript Repositories Available on: What is LeetHub? A chrome extension that automa

Qasim Wani 2.8k Dec 31, 2022
This tool allows you to test your chains.json file to see if your chains are available, syncing, or in sync.

Chains Tester This tool allows you to test your chains.json file to see if your chains are available, syncing, or in sync. This is an open source tool

Jorge S. Cuesta 9 Nov 4, 2022
Obsidian plugin to sync Pinboard.in links to Daily Notes

Obsidian Pinboard Sync An Obsidian plugin that adds links you've saved with Pinboard to your Obsidian Daily Notes, synchronizing periodically. Why? I'

Mathew Spolin 35 Dec 1, 2022
Obsidian.md plugin to sync highlights/notes from koreader

Obsidian KOReader Plugin Sync KOReader notes in your Obsidian vault. The KOReader device must be connected to the device running obsidian to let the p

Federico Granata 24 Dec 18, 2022
Get a diff view of your Obsidian Sync, File Recovery and Git version history

Version History Diff (for Sync and File Recovery Core plugins and Git) Note This plugin uses private APIs, so it may break at any time. Use at your ow

null 39 Dec 26, 2022
Sync your personal calendar to your work calendar, privately 🐒

Callibella ?? It is considered unusual among Callibella in that it gives birth to only a single baby instead of twins, the norm for Callibella. Wikiep

Yo'av Moshe 19 Oct 12, 2022
🔂 Send patches around to keep the system in sync.

The core idea is to use patches to keep the UI in sync between client and server, multiple clients, or multiple windows. It uses Immer as an interface

Webstudio 27 Sep 15, 2022