This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { atom } from "recoil"; | |
export const todoListState = atom({ | |
key: "todoListState", | |
default: [ | |
{ name: "Apples", isCompleted: false }, | |
{ name: "Eggs", isCompleted: false }, | |
{ name: "Butter", isCompleted: false }, | |
], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import { useRecoilState, atom, selector, useRecoilValue } from "recoil"; | |
const todoListState = atom({ | |
key: "todoListState", | |
default: [ | |
{ name: "Apples", isCompleted: false }, | |
{ name: "Eggs", isCompleted: false }, | |
{ name: "Butter", isCompleted: false }, | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const filteredTodos = useRecoilValue(filteredTodoListState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select value={filter} onChange={(e) => setFilter(e.target.value)}> | |
<option value="all">All</option> | |
<option value="completed">Completed</option> | |
<option value="uncompleted">Uncompleted</option> | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [filter, setFilter] = useRecoilState(todoListFilterState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const todoListFilterState = atom({ | |
key: 'todoListFilterState', | |
default: 'Hepsini göster', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import { useRecoilState, atom } from "recoil"; | |
const todoListState = atom({ | |
key: "todoListState", | |
default: [ | |
{ name: "Apples", isCompleted: false }, | |
{ name: "Eggs", isCompleted: false }, | |
{ name: "Butter", isCompleted: false }, | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const completeAt = (index) => { | |
const todos = [...todoList]; | |
const todo = todos[index]; | |
todos[index] = { name: todo.name, isCompleted: !todo.isCompleted }; | |
setTodoList(todos); | |
}; |