File tree Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { useSelector , useDispatch } from 'react-redux' ;
3+ import { Types } from '../../store/reducer' ;
34
45export default function ComponentList ( ) {
56
@@ -11,7 +12,7 @@ export default function ComponentList() {
1112 const dispatch = useDispatch ( ) ;
1213
1314 function add ( ) {
14- dispatch ( { type : 'ADD_REDUCER' , title : 'GrafQL' } )
15+ dispatch ( { type : Types . ADD , title : 'GrafQL' } )
1516 }
1617
1718 return (
Original file line number Diff line number Diff line change 11import { createStore } from 'redux'
22
3- const INITIAL_STATE = {
4- data : [
5- 'React Native' ,
6- 'ReactJS' ,
7- 'NodeJS'
8- ]
9- }
10-
11- function reducer ( state = INITIAL_STATE , action ) {
12- switch ( action . type ) {
13- case 'ADD_REDUCER' :
14- return { ...state , data : [ ...state . data , action . title ] }
15- default :
16- return state ;
17- }
18- }
3+ import reducer from './reducer'
194
205const store = createStore ( reducer )
216
Original file line number Diff line number Diff line change 1+ import { createActions , createReducer } from 'reduxsauce' ;
2+
3+ export const { Types, Creators } = createActions ( {
4+ add : [ "title" ]
5+ } )
6+
7+ const INITIAL_STATE = {
8+ data : [
9+ 'React Native' ,
10+ 'ReactJS' ,
11+ 'NodeJS'
12+ ]
13+ }
14+
15+ const add = ( state = INITIAL_STATE , action ) => {
16+ return { ...state , data : [ ...state . data , action . title ] }
17+ }
18+
19+ export default createReducer ( INITIAL_STATE , {
20+ [ Types . ADD ] : add ,
21+ } )
You can’t perform that action at this time.
0 commit comments