Recoil: Promises in initialize state doesn't work, example from docs

Created on 30 May 2020  路  3Comments  路  Source: facebookexperimental/Recoil

I'm trying to use the code from docs but the code to update state in initializeState doesn't work with promises.

<RecoilRoot
      initializeState={({ set }) => {
        // this line update the count atom
        // set({ key: "count" }, 100);

        // but in promise it doesn't work:
        Promise.all([1]).then(() => {
          set({ key: "count" }, 100);
        });
      }}
    >
<App />
</RecoilRoot>

Here the demo: https://codesandbox.io/s/strange-wescoff-pwvih?file=/src/index.js

documentation

All 3 comments

Hi @polemius. I believe this is a duplicate of either #103 or #171

@polemius - The persistence API is currently under development and will change, working on it now.. The initializeState callback doesn't support async sets. Removing that from the docs. (#209) I should probably remove those docs entirely until the API is published..

@acutmore @drarmstr Thanks 馃憤

Was this page helpful?
0 / 5 - 0 ratings