Created
October 3, 2022 20:42
-
-
Save brandonchadlange/eac7f4b030bf44f8a1fdbc060ca499a4 to your computer and use it in GitHub Desktop.
Example Todo list view model
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 useTodoListViewModel = () => { | |
const [todos, setTodos] = useState<Todo[]>([]); | |
const createTodo = (description: string) => { | |
const newTodo: Todo = { | |
description, | |
complete: false, | |
}; | |
setTodos((current) => [...current, newTodo]); | |
}; | |
return { | |
todos, | |
createTodo, | |
}; | |
}; | |
const TodoList = ({ todos }: { todos: Todo[] }) => { | |
const todoList = todos.map((todo) => <Todo todo={todo} />); | |
return <ul>{todoList}</ul>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment