File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import uuid from 'uuid/v4';
88
99const DispatchContext = createContext ( null ) ;
1010
11- const initalTodos = [
11+ const initialTodos = [
1212 {
1313 id : uuid ( ) ,
1414 task : 'Learn React' ,
@@ -70,22 +70,31 @@ const todoReducer = (state, action) => {
7070
7171const App = ( ) => {
7272 const [ filter , dispatchFilter ] = useReducer ( filterReducer , 'ALL' ) ;
73- const [ todos , dispatchTodos ] = useReducer ( todoReducer , initalTodos ) ;
73+ const [ todos , dispatchTodos ] = useReducer (
74+ todoReducer ,
75+ initialTodos
76+ ) ;
7477
7578 // Global Dispatch Function
7679 const dispatch = action =>
7780 [ dispatchTodos , dispatchFilter ] . forEach ( fn => fn ( action ) ) ;
7881
79- const filteredTodos = todos . filter ( todo => {
80- if ( filter === 'ALL' ) {
82+ // Global State
83+ const state = {
84+ filter,
85+ todos,
86+ } ;
87+
88+ const filteredTodos = state . todos . filter ( todo => {
89+ if ( state . filter === 'ALL' ) {
8190 return true ;
8291 }
8392
84- if ( filter === 'COMPLETE' && todo . complete ) {
93+ if ( state . filter === 'COMPLETE' && todo . complete ) {
8594 return true ;
8695 }
8796
88- if ( filter === 'INCOMPLETE' && ! todo . complete ) {
97+ if ( state . filter === 'INCOMPLETE' && ! todo . complete ) {
8998 return true ;
9099 }
91100
You can’t perform that action at this time.
0 commit comments