Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import React, { useReducer } from 'react';
  2. import { Input } from './components/Input'
  3.  
  4. const initialState = { todos: [] }
  5.  
  6. const reducer = (state, action) => {
  7. switch (action.type) {
  8. case 'addTodo': return {
  9. ...state,
  10. todos: [
  11. ...state.todos,
  12. { task: action.payload, completed: false }
  13. ]
  14. }
  15. }
  16. }
  17.  
  18. const App = () => {
  19. const [state, dispatch] = useReducer(reducer, initialState);
  20.  
  21. return (
  22. <>
  23. <h1>Oli's funky to-do list</h1>
  24. <Input addTodoDispatch={ dispatch } />
  25.  
  26. <ul>
  27. {state.todos.map((todo, i) =>
  28. <li key={`${i}`}>{todo.task}</li>)}
  29. </ul>
  30. </>
  31. )
  32. }
  33.  
  34. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement