Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Related tags

React Recoil
Overview

Recoil · NPM Version Node.js CI GitHub license Follow on Twitter

Recoil is an experimental set of utilities for state management with React.

Please see the website: https://recoiljs.org

Installation

The Recoil package lives in npm. To install the latest stable version, run the following command:

npm install recoil

Or if you're using yarn:

yarn add recoil

Or if you're using bower:

bower install --save recoil

Contributing

Development of Recoil happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving Recoil.

License

Recoil is MIT licensed.

Comments
  • React Native bundle

    React Native bundle

    Fixes https://github.com/facebookexperimental/Recoil/issues/99

    Additions:

    • Add the ability to set/get a batch function, which defaults to ReactBatchedUpdates.
    • Add ReactBatchedUpdates files for Web and Native that are imported to set the batch function to the renderer-specific function.
    • Add a native target to Rollup, which resolves ReactBatchedUpdates.

    Result: This gives us out of the box support for React DOM and React Native, with the library user not needing to make any changes.

    Notes: I haven't changed the use of unstable_batchedUpdates in the tests. (In fact I haven't been able to get the suite to pass on master, which I'll have another go at later, and file an issue if I'm still stuck.) But it'd be great if the maintainers or anyone with more contexts on the tests could weigh in here. It seems like we should use unstable_batchedUpdates from react-test-renderer here.

    In future, we could add a separate entry point (e.g. 'recoil/alternate-renderers') that doesn't set a batch function and doesn't depend on react-dom or react-native. We should be able to do this really easily because the infrastructure for setting the batching function to anything is available (and already exported in this PR).

    Prior art for this PR:

    enhancement help wanted CLA Signed Merged 
    opened by jacques-blom 72
  • [SSR][NextJS] Duplicate atom key during development and during production build in nextjs

    [SSR][NextJS] Duplicate atom key during development and during production build in nextjs

    Both during local development and also when building a production build, I’m getting a duplicate atom key for each key and each page using it after the first one.

    I put together a quick sandbox to demonstrate the issue: https://codesandbox.io/s/flamboyant-sea-tqlky

    The errors show up in the build log, a quick way to test is using the integrated vercel deployment button. Looking at the default nextjs example, I can‘t spot any special settings there that would prevent whatever duplication is going on from happening: https://github.com/vercel/next.js/tree/canary/examples/with-recoil That example however only makes use of recoil state on one page.

    help wanted 
    opened by janus-reith 57
  • Random

    Random "Can't perform a React state update on an unmounted component..." errors in v0.2.0.

    After upgrading to version v0.2.0 I'm getting errors like this at random components and can't figure out why it happens. All components works fine with v0.1.2. All my atoms just simple atoms without async selectors and other complicated stuff.

    Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
    at node_modules\react-native\Libraries\LogBox\LogBox.js:173:8 in registerError
    at node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
    at node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
    at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:106:4 in printWarning
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:75:16 in error
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19152:9 in warnAboutUpdateOnUnmountedFiberInDEV
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17093:40 in scheduleUpdateOnFiber
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:11003:16 in dispatchAction
    at [native code]:null in dispatchAction
    at node_modules\recoil\native\recoil.js:4309:24 in subscribeToRecoilValue$1$argument_2
    at node_modules\recoil\native\recoil.js:3321:41 in sendEndOfBatchNotifications
    at node_modules\recoil\native\recoil.js:3374:6 in Recoil_Queue.enqueueExecution$argument_1
    at node_modules\recoil\native\recoil.js:1041:0 in enqueueExecution
    at node_modules\recoil\native\recoil.js:3355:18 in useEffect$argument_0
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15561:31 in commitHookEffectListMount
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15618:35 in commitPassiveHookEffects
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18795:29 in flushPassiveEffectsImpl
    at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17650:21 in performSyncWorkOnRoot
    at [native code]:null in performSyncWorkOnRoot
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5321:31 in runWithPriority$argument_1
    at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5316:21 in flushSyncCallbackQueueImpl
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5304:28 in flushSyncCallbackQueue
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17125:30 in scheduleUpdateOnFiber
    at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:11003:16 in dispatchAction
    at [native code]:null in dispatchAction
    at node_modules\recoil\native\recoil.js:3354:2 in Batcher
    at node_modules\recoil\native\recoil.js:3556:4 in replaceState
    at node_modules\recoil\native\recoil.js:775:9 in applyActionsToStore
    at node_modules\recoil\native\recoil.js:798:9 in queueOrPerformStateUpdate
    at node_modules\recoil\native\recoil.js:841:24 in setRecoilValue
    at node_modules\recoil\native\recoil.js:4416:9 in useSetRecoilState
    at node_modules\expo-image-manipulator\build\ImageManipulator.js:4:7 in manipulateAsync
    at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
    at node_modules\regenerator-runtime\runtime.js:293:29 in invoke
    at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
    at node_modules\regenerator-runtime\runtime.js:154:27 in invoke
    at node_modules\regenerator-runtime\runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
    at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
    at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
    at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
    at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
    at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
    at [native code]:null in flushedQueue
    at [native code]:null in invokeCallbackAndReturnFlushedQueue
    

    Environment

    | software | version | ---------------------------- | ------- | expo | 40.0.1 | react | 17.0.2 | react-native | 0.63.4 | recoil | 0.2.0

    opened by chybisov 49
  • update rollup config and fix unresolved path

    update rollup config and fix unresolved path

    Hi 👋

    I followed this issue https://github.com/facebookexperimental/Recoil/issues/23, and I saw that I could help 😄

    I add a /utils in the bundle which contains RecoilUtils.js

    I fix some unresolved paths (and a twice declaration in recoil_values/Recoil_WaitFor.js thanks to the rollup messages). I'm not a rollup expert so, let me know if I did something wrong.

    Question: There is no command to run tests?

    Thanks for this amazing job :)

    CLA Signed 
    opened by tony-go 42
  • Avoid re-rendering components if selector value hasn't changed.

    Avoid re-rendering components if selector value hasn't changed.

    tl;dr: if an atom is an object and a selector returns a single property from that object, will downstream components re-render whenever ANY part of the atom changes, or only when that selector value changes? i.e. are selector output values cached or do re-renders occur whenever any of their input dependencies change? (I suspect the latter?).

    If recoil doesn't cache selector output, then I suspect my best approach is useRecoilCallback to avoid subscribing, then have something like useStateSlice() which takes a slice fn() which triggers component updates (useState/setState) when the slice value differs?

    seem right?


    background:

    This arises from a common(?) case:

    The "atom" in my case is a (firebase) document which is basically a property bag of fields. We get async updates from firebase when that data is changed (possibly external to our app - e.g. by another user, etc.).

    So if my atom is the document, I (think?) I'm hosed - any update to any field of the document will cause all downstream selectors to update and therefore all components depending on ANY part of the document to re-render.

    What I'd like is to think of selectors as a "slicing" the data, so I could have a lastName selector which picks the lastName field out of the Person document. Components depending on lastName would update only when that field is different, ignoring changes to other parts of the person.

    performance 
    opened by ehahn9 39
  • render twice on component mount (useRecoilValue, useRecoilState) no StrictMode

    render twice on component mount (useRecoilValue, useRecoilState) no StrictMode

    Hello,

    I am really excited about this project, I've played around and just notice that my component was rendered twice after it mounted even without StrictMode(in production) #75

    I've created a small example without StrictMode enabled on code sandbox: https://codesandbox.io/s/recoil-itit-double-render-jzbun

    just wondering what I am doing wrong I appreciate any help!

    performance 
    opened by NikitaBazhenov 34
  • [docs/korean] Translate official document into Korean / except pages that alstn2468 translated

    [docs/korean] Translate official document into Korean / except pages that alstn2468 translated

    • [ ] docs
      • [ ] Introduction
        • [ ] Motivation
        • [ ] Core Concepts
        • [x] Installation (@Mark-Yoo)
        • [ ] Getting Started
      • [ ] Basic Tutorial
        • [ ] Intro
        • [ ] Atoms
        • [ ] Selectors
        • [ ] Bonus: Performance (Didn't release)
      • [x] Guides
        • [x] Asynchronous Data Queries (@Mark-Yoo)
        • [x] Atom Effects (@Mark-Yoo)
        • [x] Testing (@Mark-Yoo)
        • [x] Dev Tools (@Mark-Yoo)
      • [ ] API Reference
        • [ ] Core
          • [ ] <RecoilRoot />
          • [ ] State
            • [ ] atom()
            • [ ] selector()
            • [x] Loadable (@Mark-Yoo)
            • [x] useRecoilState() (@Mark-Yoo)
            • [x] useRecoilValue() (@Mark-Yoo)
            • [x] useSetRecoilState() (@Mark-Yoo)
            • [x] useResetRecoilState() (@Mark-Yoo)
            • [x] useRecoilValueLoadable() (@Mark-Yoo)
            • [x] useRecoilStateLoadable() (@Mark-Yoo)
            • [ ] isRecoilValue()
          • [x] Snapshots
            • [x] Snapshot (@Mark-Yoo)
            • [x] useRecoilTransactionObserver() (@Mark-Yoo)
            • [x] useRecoilSnapshot() (@Mark-Yoo)
            • [x] useGotoRecoilSnapshot() (@Mark-Yoo)
          • [x] useRecoilCallback() (@Mark-Yoo)
          • [x] Misc
            • [x] useRecoilBridgeAcrossReactRoots() (@jung-han)
        • [x] Utils
          • [x] atomFamily() (@jung-han)
          • [x] selectorFamily() (@jung-han)
          • [x] constSelector() (@jung-han)
          • [x] errorSelector() (@jung-han)
          • [x] waitForAll() (@jung-han)
          • [x] waitForAny() (@jung-han)
          • [x] waitForNone() (@jung-han)
          • [x] noWait() (@jung-han)
    documentation duplicate CLA Signed 
    opened by Mark-Yoo 33
  • Support useTransition() for showing previous Recoil state with Recoil state changes.

    Support useTransition() for showing previous Recoil state with Recoil state changes.

    i realize that useTransition is bleeding edge, but i'd like to get an early handle on it. this far i've not been able to figure out any combination of parts to get useTransition to work, and i can't find any examples online. all my imports work and i'm following the code like this.

        recoil: 0.1.1
        react: 0.0.0-experimental-4ead6b530
        react-dom: 0.0.0-experimental-4ead6b530
    

    and using the concurrent pattern:

    ReactDOM.unstable_createRoot(document.getElementById("root")).render(
      <BrowserRouter>
        <Route path="/" component={App} />
      </BrowserRouter>
    );
    

    and an otherwise typical and working <Suspense /> pattern:

    import React, { Suspense, useState, unstable_useTransition as useTransition } from "react";
    import { atom, selector, useRecoilState } from "recoil";
    
    export const baseState = atom({
      key: "base",
      default: 100,
    });
    
    export const resourceState = selector({
      key: "resource",
      get: ({ get }) => {
        const base = get(baseState);
        return new Promise(resolve => {
          setTimeout(() => {
            resolve(base);
          }, 2000);
        });
      },
      set: ({ set }, value) => {
        set(baseState, value);
      },
    });
    
    const UseTransitionEample = () => {
      const [resource, setResource] = useRecoilState(resourceState);
      const [startTransition, isPending] = useTransition({ timeoutMs: 3000 });
    
      return (
        <>
          <div>resource: {resource}</div>
          <div>isPending: {isPending ? "true" :  "false"}</div>
          <button onClick={() =>
              startTransition(() => {
                setResource(resource + 1);
              })
          }>Update</button>
        </>
      );
    }
    
    const SuspenseWrapper = () => (
      <Suspense fallback={<div>"Loading..."</div>}>
        <UseTransitionEample />
      </Suspense>
    );
    
    export default SuspenseWrapper;
    

    In the above code clicking the button results in the "Loading..." fallback being presented for the full duration of the "load".

    enhancement 
    opened by trebor 29
  • fix selectorGetter performance issue

    fix selectorGetter performance issue

    • motivation: the getter is call setDepsInStore every time, harm the performance when multiple call the getter
    • notes: this pr just a demo, I don't known is this feasible. please give me a confirm, and I will make some further change with testcases

    #914 Please refer this issue for detail

    CLA Signed performance 
    opened by thomaszdxsn 28
  • Test multiple versions of React

    Test multiple versions of React

    Summary: Update GitHub CI actions to do matrix testing with multiple versions of React in addition to OS and Node versions.

    This allows us to test both React 17 and React 18 with new concurrent and strict modes.

    how_to_regex_garabatokid

    regex_train

    iknowthis_regex

    Differential Revision: D33196989

    CLA Signed tests fb-exported build / infra 
    opened by drarmstr 28
  • How to refresh/invalidate an asynchronous selector?

    How to refresh/invalidate an asynchronous selector?

    Selectors can be used to asynchronously fetch data from an API. But how is it possible to trigger a re-fetch of this data?

    Given this selector:

    const todosState = selector({
      key: "todosState",
      get: async () => {
        const result = await fetch("https://example.com/todos");
        const todos = await result.json();
        return todos;
      },
    });
    

    In a scenario where a user wanted to reload his todos, because he knows his coworker added a new todo to the list. How would he trigger this selector to re-fetch the todos from the API?

    opened by philippta 27
  • Bump json5 from 1.0.1 to 1.0.2 in /packages-ext/todo-example

    Bump json5 from 1.0.1 to 1.0.2 in /packages-ext/todo-example

    Bumps json5 from 1.0.1 to 1.0.2.

    Release notes

    Sourced from json5's releases.

    v1.0.2

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295). This has been backported to v1. (#298)
    Changelog

    Sourced from json5's changelog.

    Unreleased [code, diff]

    v2.2.3 [code, diff]

    v2.2.2 [code, diff]

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1 [code, diff]

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)

    v2.2.0 [code, diff]

    • New: Accurate and documented TypeScript declarations are now included. There is no need to install @types/json5. (#236, #244)

    v2.1.3 [code, diff]

    • Fix: An out of memory bug when parsing numbers has been fixed. (#228, #229)

    v2.1.2 [code, diff]

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    CLA Signed dependencies 
    opened by dependabot[bot] 0
  • Bug: DefaultValue returned from selector get instead of actual default

    Bug: DefaultValue returned from selector get instead of actual default

    I have the following code:

    import { get, set } from "idb-keyval";
    import type { AtomEffect } from "recoil";
    import { DefaultValue, atom, selector } from "recoil";
    
    export const syncIdbEffect =
      <T>(dbKey: string): AtomEffect<T> =>
      ({ onSet, setSelf }) => {
        setSelf(
          get(dbKey).then((savedVal: T | null) =>
            savedVal !== null || savedVal !== undefined ? savedVal : new DefaultValue(),
          ),
        );
        onSet((newVal, oldVal) => {
          if (newVal === oldVal) return;
    
          set(dbKey, newVal);
        });
      };
    
    const tokenState = atom<string | undefined>({
      key: "tokenState",
      default: undefined,
      effects: [syncIdbEffect("token")],
    });
    export const isAuthedState = selector<boolean>({
      key: "isAuthedState",
      get: ({ get }) => {
        const refreshToken = get(tokenState);
        // MARK: At this stage refresh is of type "DefaultValue {}". TypeScript thinks that only string | undefined is the type
        return !!refreshToken;
      },
    });
    

    It's failing because the DefaultValue object is being returned from the get, where I'd expect the default to be undefined (see the MARK comment)

    I'm using Recoil v0.7.6

    opened by ayroblu 0
  • Atom is not waiting for promise used in setSelf

    Atom is not waiting for promise used in setSelf

    Hey folks 👋 I got this issue with initializing atom in effect by using promise for setSelf. I will try to describe the problem:

    • There are two atoms. Both are initialized in effect by using setSelf.
    • There is a selector (selectAtomValues) that wraps both of them and concatenates the results of atoms.
    • There is also another selector (firstAtomStateSelector) that only wraps one of those atoms and returns the value of the atom
    • Now when we use only atoms in selectAtomValues everything works fine (you can try by uncommenting line 38)
    • But if we use firstAtomStateSelector to get firstAtomState value it will not wait for secondAtomState and it displays default value of the atom. Later (after 3s delay) you can see the promise resolves to correct value but nothing is re-rendered. And even if it would be re-rendered it is probably not correct behaviour.

    Here is repro: https://codesandbox.io/s/recoil-issue-with-promise-effect-l6ddpd?file=/src/App.js

    opened by xotahal 0
  • Build times out when doing `next build`

    Build times out when doing `next build`

    Doing async on selector's get causes build to time out.

    Example project: https://github.com/minakawa-daiki/recoil-build-test

    If you remove the async in the following line, the build will pass without incident. https://github.com/minakawa-daiki/recoil-build-test/blob/main/src/testState.ts#L10

    I believe this is a bug in Recoil.

    opened by minakawa-daiki 0
  • Recoil docs Markdown implementation

    Recoil docs Markdown implementation

    I'm curious how did you implement markdown:

    For example, for this page

    There's according markdown page, but I'm not sure how they are linked, or how to run the repository, can somebody guide me?

    opened by 1alexvash 0
Releases(0.7.6)
  • 0.7.6(Oct 11, 2022)

    • Expose flag to disable "duplicate atom key" checking / logging, as it was too noisy in environments such as NextJS or some dev environments using Fast Refresh. (#733, #2020, #2046)
      • Import RecoilEnv from the recoil package, and set RecoilEnv.RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED = false in code to disable the checking and logging.
      • We also support process.env.RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED=false in NodeJS environments such as NextJs
      • Caution: This disables all checks for duplicate atom keys including legitimate errors, so use with caution!
    • Workaround for React 18 environments with nested renderers that don't support useSyncExternalStore(). (#2001, #2010)
    Source code(tar.gz)
    Source code(zip)
  • 0.7.5(Aug 11, 2022)

    • Fix useRecoilSnapshot() with React's Fast Refresh during development (#1891)
    • Fix useRecoilSnapshot() and recoil-sync with changed browser behavior starting with Chrome v104 (#1943, #1936)
    Source code(tar.gz)
    Source code(zip)
  • 0.7.4(Jun 22, 2022)

  • 0.7.3(Jun 2, 2022)

    • Enable atoms and selectors to be used in family parameters (#1172)
    • Add parentStoreID_UNSTABLE to atom effects which is the ID of the parent store it cloned from, such as the host <RecoilRoot> store for useRecoilCallback() snapshots. (#1744)
    • Atom effects can initialize or set atoms to wrapped values (#1681)
    Source code(tar.gz)
    Source code(zip)
  • 0.7.2(Apr 14, 2022)

    • Selector cache lookup optimizations (#1720, #1736)
    • Allow async selectors to re-evaluate when async dependencies are discovered with stale state (#1736)
    Source code(tar.gz)
    Source code(zip)
  • 0.7.1(Apr 13, 2022)

    Typing

    • Add explicit children prop to <RecoilRoot> and useRecoilBridgeAcrossReactRoots_UNSTABLE() for TypeScript for @types/react with React 18 (#1718, #1717, #1726, #1731)
    • Update typing for family parameters to better support Map, Set, and classes with toJSON(). (#1709, #1703)

    Fixes

    • Avoid dev-mode console error with React 18 when using shared async selectors across multiple <RecoilRoot>'s. (#1712)
    • Cleanup potential memory leak when using async selectors. (#1714)
    • Fix potentially hung async selectors when shared across multiple roots that depend on atoms initialized with promises that don't resolve. (#1714)
    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(Apr 1, 2022)

    New Features

    • The default value is now optional for atom() and atomFamily(). If not provided the atom will initialize to a pending state. (#1639)
    • Add getStoreID() method to Snapshot (#1612)
    • Publish RecoilLoadable.loading() factory for making an async Loadable which never resolves. (#1641)

    Breaking Changes

    • Selector's get() and Atom's default can now accept a Loadable to put the node in that state. If you wish to store a Loadable, Promise, or RecoilValue directly you can wrap it with selector.value() or atom.value(). (#1640)
    • useRecoilCallback() now provides a snapshot for the latest state when the callback is called instead of the latest rendered state, which had issues (#1610, #1604)

    Improvements / Optimizations

    • Automatically retain snapshots for the duration of async callbacks. (#1632)
    • Optimization for more selector dependencies. 2x improvement with 100 dependencies, 4x with 1,000, and now able to support 10,000+. (#1651, #1515, #914)
    • Better error reporting when selectors provide inconsistent results (#1696)

    Fixes

    • Avoid spurious console errors from effects when calling setSelf() from onSet() handlers. (#1589, #1582)
    • Freezing user values in dev mode now works in JS environments without the Window interface. (#1571)
    Source code(tar.gz)
    Source code(zip)
  • 0.6.1(Jan 31, 2022)

  • 0.6.0(Jan 29, 2022)

    React 18

    • Leverage new React 18 APIs for improved safety and optimizations. (#1488)
    • Fixes for <StrictMode> (#1473, #1444, #1509).
    • Experimental support for useTransition() using hooks with _TRANSITION_SUPPORT_UNSTABLE suffix. (#1572, #1560)
    • Recoil updates now re-render earlier:
      • Recoil and React state changes from the same batch now stay in sync. (#1076)
      • Renders now occur before transaction observers instead of after.

    New Features

    • Add refresh() to the useRecoilCallback() interface for refreshing selector caches. (#1413)
    • Callbacks from selector's getCallback() can now mutate, refresh, and transact Recoil state, in addition to reading it, for parity with useRecoilCallback(). (#1498)
    • Recoil StoreID's for <RecoilRoot> and Snapshot stores accessible via useRecoilStoreID() hook (#1417) or storeID parameter for atom effects (#1414).
    • RecoilLoadable.all() and RecoilLoadable.of() now accept either literal values, async Promises, or Loadables. (#1455, #1442)
    • Add .isRetained() method for Snapshots and check if snapshot is already released when using .retain() (#1546)

    Other Fixes and Optimizations

    • Reduce overhead of snapshot cloning
      • Only clone the current snapshot for callbacks if the callback actually uses it. (#1501)
      • Cache the cloned snapshots from callbacks unless there was a state change. (#1533)
    • Fix transitive selector refresh for some cases (#1409)
    • Fix some corner cases with async selectors and multiple stores (#1568)
    • Atom Effects
      • Run atom effects when atoms are initialized from a set during a transaction from useRecoilTransaction_UNSTABLE() (#1466, #1569)
      • Atom effects are cleaned up when initialized by a Snapshot which is released. (#1511, #1532)
      • Unsubscribe onSet() handlers in atom effects when atoms are cleaned up. (#1509)
      • Call onSet() when atoms are initialized with <RecoilRoot initializeState={...} > (#1519, #1511)
    • Avoid extra re-renders in some cases when a component uses a different atom/selector. (#825)
    • <RecoilRoot> will only call initializeState() once during the initial render. (#1372)
    • Lazily compute the properties of useGetRecoilValueInfo_UNSTABLE() and Snapshot#getInfo_UNSTABLE() results (#1549)
    • Memoize the results of lazy proxies. (#1548)

    Breaking Changes

    • Rename atom effects from effects_UNSTABLE to just effects, as the interface is mostly stabilizing. (#1520)
    • Atom effect initialization takes precedence over initialization with <RecoilRoot initializeState={...} >. (#1509)
    • useGetRecoilValueInfo_UNSTABLE() and Snapshot#getInfo_UNSTABLE() always report the node type. (#1547)
    • The 0.3 release introduced the need to retain Snapshots for later use, but it was mostly a warning. Now it is necessary to retain a Snapshot for asynchronous selectors to resolve. See the documentation here and here. Future releases will further enforce this as garbage collection is released.
    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Nov 8, 2021)

  • 0.5.1(Nov 6, 2021)

  • 0.5.0(Nov 4, 2021)

    • Added useRecoilRefresher_UNSTABLE() hook which forces a selector to re-run it's get(), and is a no-op for an atom. (#972, #1294, #1302)
    • Atom effect improvements:
      • Add getLoadable(), getPromise(), and getInfo_UNSTABLE() to Atom Effects interface for reading other atoms. (#1205, #1210)
      • Add isReset parameter to onSet() callback to know if the atom is being reset or not. (#1358, #1345)
    • Loadable improvements:
      • Publish RecoilLoadable interface with factories and type checking for Loadables. (#1263, #1264, #1312)
      • Ability to map Loadables with other Loadables. (#1180)
      • Re-implement Loadable as classes. (#1315)
    • Improved dev-mode checks:
      • Atoms freeze default, initialized, and async values. Selectors should not freeze upstream dependencies. (#1261, #1259)
      • Perform runtime check that required options are provided when creating atoms and selectors. (#1324)
    • Allow class instances in family parameters for Flow
    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(Aug 26, 2021)

    • Performance optimizations to suppress re-rendering components:
      • When subscribed selectors evaluate to the same value. (#749, #952)
      • On initial render when not using React Concurrent Mode (#820)
      • When selector async deps resolve, but React re-renders before chained promises have executed.
    • Fixed #1072 where in some cases selectors with async deps would not update in response to state updates
    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Jul 30, 2021)

    New Features

    • Selector cache configuration: introduced cachePolicy_UNSTABLE option for selectors and selector families. This option allows you to control the behavior of how the selector evicts entries from its internal cache.
    • Improved useRecoilTransaction_UNSTABLE() hook for transactions with multiple atoms (#1085)

    Fixes and Optimizations

    • Fix TypeScript typing for selectorFamily(), getCallback(), useGetRecoilValueInfo(), and Snapshot#getNodes() (#1060, #1116, #1123)
    • Allow mutable values in selectors to be used with waitFor*() helpers (#1074, #1096)
    • Atom Effects fixes:
      • Fix onSet() handler to get the proper new value when an atom is reset or has an async default Promise that resolves (#1059, #1050, #738) (Slightly breaking change)
      • Fix support for multiple Atom effects cleanup handlers (#1125)
      • Fix selector subscriptions when atoms with effects are initialized via a Snapshot (#1135, #1107)
    • Optimization for async selectors when dependencies resolve to cached values (#1037)
    • Remove unnecessary warning message (#1034, #1062)
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(May 18, 2021)

  • 0.3.0(May 14, 2021)

    Breaking Changes

    For supporting garbage collection in the future there is a slight breaking change that Snapshot's will only be valid for the duration of the callback or render. A new retain() API can be used to persist them longer. This is not enforced yet, but Recoil will now provide a warning in dev-mode if a Snapshot is used past its lifetime. (#1006)

    New Features / Improvements

    • Add override prop to <RecoilRoot> (#973)
    • Add getCallback() to selector evaluation interface (#989)
    • Improved TypeScript and Flow typing for Loadables (#966, #1022)

    Performance Optimizations

    • Improve scalability (time and memory) of Atom families by cleaning up a legacy feature.

    Bug Fixes

    • Throwing an error in an async selector should be properly caught by <ErrorBoundary>'s (#998, #1017)
    • Fix for Atom Effects onSet() should not be called when triggered from setSelf() initializing with a Promise or from the same onSet() handler. (#974, #979, #953, #986)
    • Improved support for Safari (#967, #609)
    • Objects stored in selectors are properly frozen in dev mode (#911)
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Mar 31, 2021)

    0.2.0 (2021-3-18)

    Major improvements

    • More reliable async selectors
    • Improved performance using HAMT data structures (b7d1cfddec66dae).

    Other improvements

    • Changed semantics of waitForAny() such that it will always return loadables unless everything is loading. This better aligns behaviour of waitForAny() and waitForNone()
    • Added a waitForAllSettled helper analogous to Promise.allSettled. (4c95591)
    • Friendly error message for misuse of useRecoilCallback (#870)
    • Friendly error message if you try to use an async function as a selector setter, which is not uspported. (#777)
    • Improved React Native support. (#748, #702)
    • Added useGetRecoilValueInfo_UNSTABLE() hook for dev tools. (#713, #714)

    Bug fixes

    • Selectors now treat any non-Promise that is thrown as an error, rather than only instances of Error. (f0e66f727)
    • A child of RecoilRoot could sometimes have its state updated after being unmounted. (#917)
    • The error message for missing RecoilRoot wasn't displayed on React experimental releases. (#712)
    • IE 11 compatibility (#894, d27c800d8)
    • Errors shouldn't be frozen (#852)
    • Atom effects could fail to initialize atoms in certain cases (#775).
    • Async selectors would fail with multiple React roots (a618a3).
    Source code(tar.gz)
    Source code(zip)
  • 0.1.2(Oct 30, 2020)

  • 0.1.1(Oct 30, 2020)

  • 0.0.13(Sep 23, 2020)

  • 0.0.12(Sep 16, 2020)

  • 0.0.11(Sep 15, 2020)

    • Experimental React Concurrent Mode support
    • Performance improvements
    • Flow types and improved TypeScript types
    • ES, CommonJS, and UMD packages
    • Synchronization Across React Roots
    • Preliminary Developer Tools API
    • Test Infrastructure Fixes
    Source code(tar.gz)
    Source code(zip)
  • 0.0.10(Jun 18, 2020)

  • 0.0.9(Jun 18, 2020)

    Features

    • TypeScript support now rolled into Recoil repository and package.
    • Recoil Snapshot API for observing and managing global Recoil state.

    Improvements

    • Throw error with meaningful message if user doesn't use an atom or selector with most Recoil hooks (#205) - Thanks @alexandrzavalii
    • Improve testing (#321, #318, #294, #262, #295) - Thanks @aaronabramov, @Komalov, @mondaychen, @drarmstr, and @tyler-mitchell
    • Improve open-source build (#249, #203, #33) - Thanks to @tony-go, @acutmore, and @jaredpalmer

    Bug Fixes

    • Some fixes for Server Side Rendering, though we do not officically support it yet. (#233, #220, #284) - Thanks @fyber-LJX, @Chrischuck, and @aulneau
    • Fix selectors recording dependency subscriptions in some cases (#296) - Thanks @drarmstr
    • Fix updaters in useRecoilCallback() getting current state (#260) - Thanks @drarmstr
    • Fix error messages when throwing certain errors in the open-source build. (#199) - Thanks @jonthomp
    • Reduce Flow errors for open-source builds (#308) - Thanks @Komalov
    Source code(tar.gz)
    Source code(zip)
  • 0.0.8(Jun 2, 2020)

    Bug Fixes

    • Build system and repository syncing fixed.
    • Fixed a bug where atoms that stored self-referential structures would cause an infinite loop. (#153)
    • Fixed bugs affecting Server-Side Rendering. (#53)

    Features

    • TypeScript support is now available via DefinitelyTyped.
    • atomFamily and selectorFamily: these provide a standard way to create atoms and selectors using memoized functions. Compared with doing this yourself, in the future these will help with memory management.
    • noWait, waitForNone, waitForAny, waitForAll: helpers for concurrency and other advanced logic in async selectors.
    • constSelector and errorSelector: selectors that always evaluate to a constant or always throw an error.
    • readOnlySelector: wraps a read-write
    Source code(tar.gz)
    Source code(zip)
Owner
Facebook Experimental
These are Facebook projects that are not necessarily used in production but are being developed in the open nevertheless.
Facebook Experimental
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
experimental project for babel-plugin-mutable-react-state

Goalist Mutable React Example This example is an attempt to work with babel-plugin-mutable-react-state on a simpler project to see how complicated wou

Reaper 1 Jun 7, 2022
An experimental hover effect, where a content preview is shown while a mini map indicates the position of the cursor.

Hover Preview Effect with Mini Map An experimental hover effect, where a content preview is shown while a mini map indicates the position of the curso

Codrops 27 Dec 29, 2022
A state management library for React, heavily inspired by vuex

Vuex - But for React! ⚛ If you know vuex, you know it's as close as we get to a perfect state management library. What if we could do this in the reac

Dana Janoskova 103 Sep 8, 2022
Tiny and powerful state management library.

BitAboutState Tiny and powerful React state management library. 100% Idiomatic React. Install npm install --save @bit-about/state Features 100% Idioma

null 53 Nov 5, 2022
Learning how to use redux - a state management library

Redux Learning how to use redux - a state management library What is Redux? Redux is a state management library for JS apps. It centralizes applicatio

Melvin Ng 3 Jul 18, 2022
Create a performant distributed context state by synergyzing atomar context pieces and composing reusable state logic.

Synergies Create a performant distributed context state by synergyzing atomar context pieces and composing reusable state logic. synergies is a tiny (

Lukas Bach 8 Nov 8, 2022
Build Instagram 2.0 with Next.js (Firebase v9, Tailwind CSS, NextAuth, Recoil) for the Education Purpose..

This example shows how to use Tailwind CSS (v3.0) with Next.js. It follows the steps outlined in the official Tailwind docs.

Parimal Nakrani 1 Dec 24, 2021
🐻 Bear necessities for state management in React

A small, fast and scaleable bearbones state-management solution. Has a comfy api based on hooks, isn't boilerplatey or opinionated, but still just eno

Poimandres 25.5k Jan 9, 2023
🏁 High performance subscription-based form state management for React

You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of React Final Form.

Final Form 7.2k Jan 7, 2023
🔮 tiny robust state management

?? snapstate tiny robust state management ?? npm install @chasemoskal/snapstate ??️ watch for changes to properties ??️ track only the properties you

Chase Moskal 5 Dec 23, 2022
A tiny package for JavaScript Web App's state management based on RxJS & Immer

A tiny package for JavaScript Web App's state management based on RxJS & Immer

Xiao Junjiang 12 Oct 19, 2022
Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement.

useAsyncQuery Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement. Usage

Alasdair McLeay 7 Nov 16, 2022
WPPConnect/mobile is an open source project with the objective of automating whatsapp web using the android or ios mobile browser and being able to perform all the functions of our wa-js project

WPPConnect/mobile is an open source project with the objective of automating whatsapp web using the android or ios mobile browser and being able to perform all the functions of our wa-js project, so it is possible to create a customer service, media sending, intelligence recognition based on artificial phrases and many other things, use your imagination to change and modify this project or collaborate on improvements...

null 11 Dec 28, 2022
Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.

Onsen UI - Cross-Platform Hybrid App and PWA Framework Onsen UI is an open source framework that makes it easy to create native-feeling Progressive We

null 8.7k Jan 8, 2023
Vtexio-react-apps - Apps react para plafaforma VTEX.

Projeto Modal + Apps Extras Projeto modal setando cookies. Desenvolvido em React + TypeScript para aplicação em e-commerce VTEXIO. ?? Este projeto se

Marcelo 1 Jan 3, 2022
The Power CAT code components are a set of Power Apps component framework (PCF) controls that can be used to enhance power apps.

Power CAT code components The Power CAT code components are a set of Power Apps component framework (PCF) controls that can be used to enhance power a

Microsoft 70 Jan 2, 2023
A free book that talks about design patterns/techniques used while developing with React.

React in patterns ?? A free book that talks about design patterns/techniques used while developing with React. Book GitBook Web PDF Mobi ePub Translat

Krasimir Tsonev 12.3k Jan 7, 2023
A Higher Order Component using react-redux to keep form state in a Redux store

redux-form You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of Redux

Redux Form 12.6k Jan 3, 2023