facebookexperimental / Recoil

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.
https://recoiljs.org/
MIT License
19.59k stars 1.18k forks source link

What is "store" in this example #2197

Open jkjustjoshing opened 1 year ago

jkjustjoshing commented 1 year ago

I think this is a documentation bug. In the example here: https://recoiljs.org/docs/guides/atom-effects#compared-to-react-effects is the following code snippet:

const myState = atom({key: 'Key', default: null});

function MyStateEffect(): React.Node {
  const [value, setValue] = useRecoilState(myState);
  useEffect(() => {
    // Called when the atom value changes
    store.set(value);
    store.onChange(setValue);
    return () => { store.onChange(null); }; // Cleanup effect
  }, [value]);
  return null;
}

function MyApp(): React.Node {
  return (
    <div>
      <MyStateEffect />
      ...
    </div>
  );
}

What is the store variable? Is that equal to value?

hinsencamp commented 1 year ago

Also stumped over this!

vm-agnislav commented 1 year ago

Hi guys. THe store here is a 3rd party storage, e.g. MMKV.

jkjustjoshing commented 1 year ago

That makes sense. For a documentation example, that really needs to be made more explicit then. Either a large comment explaining "external store here!", or maybe setting/getting from localStorage. Something so that a beginner doesn't think there's Recoil magic they've missed from elsewhere in the documentation.

vm-agnislav commented 1 year ago

I'm not sure we can expect it in near future, as the recoil looks... abandoned?