Skip to content

Instantly share code, notes, and snippets.

@mohanramphp
Created January 9, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohanramphp/0f37c309a468cd8ad6fb8b9e6d42ee85 to your computer and use it in GitHub Desktop.
Save mohanramphp/0f37c309a468cd8ad6fb8b9e6d42ee85 to your computer and use it in GitHub Desktop.
Todos component using React hook
import React, { useReducer } from 'react';
import { TodoForm } from './TodoForm';
import { TodoList } from './TodoList';
import { TodoReducer, TodosDispatch } from './TodoReducer';
export const Todos = ({ todos }) => {
const [state, dispatch] = useReducer(TodoReducer, todos);
return (
<div className="todos-container">
<TodosDispatch.Provider value={dispatch}>
<TodoForm></TodoForm>
<TodoList todos={state}></TodoList>
</TodosDispatch.Provider>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment