Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created May 19, 2020 15:51
Show Gist options
  • Save ozcanzaferayan/a1f05e1d7feede3154053498faff4c38 to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/a1f05e1d7feede3154053498faff4c38 to your computer and use it in GitHub Desktop.
const filteredTodoListState = selector({
key: 'filteredTodoListState',
get: ({get}) => {
const filter = get(todoListFilterState);
const list = get(todoListState);
switch (filter) {
case 'completed':
return list.filter((item) => item.isCompleted);
case 'uncompleted':
return list.filter((item) => !item.isCompleted);
default: // all
return list;
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment