Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created May 19, 2020 15:59
Show Gist options
  • Save ozcanzaferayan/9e6f17c1722763873cf66eb52b81289a to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/9e6f17c1722763873cf66eb52b81289a to your computer and use it in GitHub Desktop.
import { selector } from "recoil";
import { todoListFilterState, todoListState } from "./atoms";
export 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