File tree Expand file tree Collapse file tree 5 files changed +44
-20
lines changed Expand file tree Collapse file tree 5 files changed +44
-20
lines changed Original file line number Diff line number Diff line change 5
5
"dependencies" : {
6
6
"react" : " ^15.6.1" ,
7
7
"react-dom" : " ^15.6.1" ,
8
+ "react-redux" : " ^5.0.5" ,
8
9
"react-scripts" : " 1.0.10" ,
9
10
"redux" : " ^3.7.2" ,
10
11
"redux-logger" : " ^3.0.6"
Original file line number Diff line number Diff line change @@ -3,12 +3,9 @@ import './App.css';
3
3
4
4
import Stories from './Stories' ;
5
5
6
- const App = ( { stories , onArchive } ) =>
6
+ const App = ( ) =>
7
7
< div className = "app" >
8
- < Stories
9
- stories = { stories }
10
- onArchive = { onArchive }
11
- />
8
+ < Stories />
12
9
</ div >
13
10
14
11
export default App ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import { connect } from 'react-redux' ;
3
+ import { doArchiveStory } from '../actions/archive' ;
4
+ import { getReadableStories } from '../selectors/story' ;
2
5
import './Stories.css' ;
3
6
4
7
import Story from './Story' ;
@@ -51,4 +54,15 @@ const StoriesHeader = ({ columns }) =>
51
54
) }
52
55
</ div >
53
56
54
- export default Stories ;
57
+ const mapStateToProps = state => ( {
58
+ stories : getReadableStories ( state ) ,
59
+ } ) ;
60
+
61
+ const mapDispatchToProps = dispatch => ( {
62
+ onArchive : id => dispatch ( doArchiveStory ( id ) ) ,
63
+ } ) ;
64
+
65
+ export default connect (
66
+ mapStateToProps ,
67
+ mapDispatchToProps
68
+ ) ( Stories ) ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
+ import { Provider } from 'react-redux' ;
3
4
import App from './components/App' ;
4
5
import store from './store' ;
5
- import { getReadableStories } from './selectors/story' ;
6
- import { doArchiveStory } from './actions/archive' ;
7
6
import './index.css' ;
8
7
import registerServiceWorker from './registerServiceWorker' ;
9
8
10
- function render ( ) {
11
- ReactDOM . render (
12
- < App
13
- stories = { getReadableStories ( store . getState ( ) ) }
14
- onArchive = { id => store . dispatch ( doArchiveStory ( id ) ) }
15
- /> ,
16
- document . getElementById ( 'root' )
17
- ) ;
18
- }
19
-
20
- store . subscribe ( render ) ;
21
- render ( ) ;
9
+ ReactDOM . render (
10
+ < Provider store = { store } >
11
+ < App />
12
+ </ Provider > ,
13
+ document . getElementById ( 'root' )
14
+ ) ;
22
15
23
16
registerServiceWorker ( ) ;
You can’t perform that action at this time.
0 commit comments