File tree Expand file tree Collapse file tree 9 files changed +54
-205
lines changed Expand file tree Collapse file tree 9 files changed +54
-205
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import logo from './logo.svg' ;
3- import './App.css' ;
2+ import { Provider } from 'react-redux' ;
3+
4+ import store from './store'
5+ import ComponentList from './components/ComponentList' ;
46
57function App ( ) {
68 return (
7- < div className = "App" >
8- < header className = "App-header" >
9- < img src = { logo } className = "App-logo" alt = "logo" />
10- < p >
11- Edit < code > src/App.js</ code > and save to reload.
12- </ p >
13- < a
14- className = "App-link"
15- href = "https://reactjs.org"
16- target = "_blank"
17- rel = "noopener noreferrer"
18- >
19- Learn React
20- </ a >
21- </ header >
22- </ div >
9+ < Provider store = { store } >
10+ < ComponentList />
11+ </ Provider >
2312 ) ;
2413}
2514
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { useSelector , useDispatch } from 'react-redux' ;
3+
4+ export default function ComponentList ( ) {
5+
6+ const qty = 20
7+
8+ const list = useSelector (
9+ state => state . data . slice ( 0 , qty )
10+ , [ qty ] ) ;
11+ const dispatch = useDispatch ( ) ;
12+
13+ function add ( ) {
14+ dispatch ( { type : 'ADD_REDUCER' , title : 'GrafQL' } )
15+ }
16+
17+ return (
18+ < >
19+ < ul >
20+ { list . map ( item => < li key = { item } > { item } </ li > ) }
21+ </ ul >
22+ < button type = "button" onClick = { add } > ADD</ button >
23+ </ >
24+ ) ;
25+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import ReactDOM from 'react-dom' ;
3- import './index.css' ;
43import App from './App' ;
5- import * as serviceWorker from './serviceWorker' ;
64
75ReactDOM . render ( < App /> , document . getElementById ( 'root' ) ) ;
8-
9- // If you want your app to work offline and load faster, you can change
10- // unregister() to register() below. Note this comes with some pitfalls.
11- // Learn more about service workers: https://bit.ly/CRA-PWA
12- serviceWorker . unregister ( ) ;
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { createStore } from 'redux'
2+
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+ }
19+
20+ const store = createStore ( reducer )
21+
22+ export default store ;
You can’t perform that action at this time.
0 commit comments