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.5k stars 1.18k forks source link

Performance best practices? #1869

Open FezVrasta opened 2 years ago

FezVrasta commented 2 years ago

Do you think it would be a good idea to provide a "performance best practices" page in the docs?

A possible example would be:

// Subscribing to atoms can be expensive and lead to unnecessary rerenders
const value = useRecoilValue(myAtom);
const action = useCallback(() => {
  // do something with value
}, [value]);

// Consider using `useRecoilCallback` to only access the atom state when needed instead
const action = useRecoilCallback(({ snapshot }) => async () => {
  const value = await snapshot.getPromise(myAtom);
  // do something with value
}, []);
aussio commented 2 years ago

This page already exists, so maybe it would make sense to add here? https://recoiljs.org/docs/basic-tutorial/performance/

Relatedly, I found that page via google. It seems that maybe the docs need updated to include a link to it?