Skip to content

Commit a65eefc

Browse files
author
Brady Stilwell
committed
add and configure redux store
1 parent f2499bd commit a65eefc

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

client/components/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import Hello from './Hello';
33
import World from './World';
44

55
export default class App extends React.Component {
6+
67
render () {
8+
const {dispatch, getState} = this.props.store;
79
return (
810
<div>
911
<Hello/>

client/main.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import App from './components/App';
1+
import React from 'react'
2+
import { render } from 'react-dom'
3+
import { Provider } from 'react-redux'
4+
import { createStore, applyMiddleware, compose } from 'redux'
5+
import rootReducer from './reducers/rootReducer'
6+
import App from './components/App'
47

5-
ReactDOM.render(<App />, document.getElementById('container'));
8+
const initialState = {
9+
zipCode: {},
10+
legislators: []
11+
};
12+
13+
const store = createStore(rootReducer, {state: initialState}, compose(
14+
window.devToolsExtension ? window.devToolsExtension() : f => f
15+
));
16+
17+
render(
18+
<App
19+
store={store}
20+
/>,
21+
document.getElementById('container')
22+
);
23+
24+
store.subscribe(render);

client/reducers/rootReducer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function (state={foo: 'bar'}, action) {
2+
switch(action.type) {
3+
case "FOO": {
4+
return {init: true}
5+
}
6+
default: return state
7+
}
8+
9+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"express": "^4.14.0",
1717
"react": "^15.3.1",
1818
"react-dom": "^15.3.1",
19+
"react-redux": "^4.4.6",
20+
"redux": "^3.6.0",
1921
"request": "^2.78.0",
2022
"request-promise": "^4.1.1",
2123
"winston": "^2.3.0"
@@ -45,6 +47,7 @@
4547
"nodemon": "^1.10.2",
4648
"npm": "^3.10.9",
4749
"react-addons-test-utils": "^15.3.1",
50+
"redux-devtools": "^3.3.1",
4851
"run-sequence": "^1.2.2",
4952
"supertest": "^2.0.1",
5053
"webpack": "^1.13.2",

0 commit comments

Comments
 (0)