MuddyBootsCode / recoil-tryout

Trying out the new Recoil state management library
https://recoil-tryout.now.sh
9 stars 1 forks source link

The correct usage of Rocoil 👏 #1

Open littlehaker opened 4 years ago

littlehaker commented 4 years ago

This repo seems to be the correct usage of recoil.

The itemList atom only has ids rather than entities.

Many other tryouts use itemList to represent entities.

const todoItemsState = atom({
  key: 'todoItemsState',
  default: [
    { id: 1, text: 'Learn React', isComplete: true },
    { id: 2, text: 'Learn Recoil', isComplete: true },
    { id: 3, text: 'Write Todo App', isComplete: true },
  ],
});

In that case, the state change of each entity will create a new itemList instance, which leads to unnecessary renders.

MuddyBootsCode commented 2 years ago

Thank you :)