From 0beaef4fba843fc893fb73de8ad3de0bf4fae197 Mon Sep 17 00:00:00 2001 From: Martin Nordby Johansen Date: Mon, 25 Feb 2019 11:23:39 +0100 Subject: [PATCH] #4 setup redux boilerplate and folder structure --- src/App.js | 12 +++++++++++- src/index.js | 8 +++++++- src/reducers/filterReducer.js | 5 +++++ src/reducers/queryReducer.js | 5 +++++ src/reducers/resultReducer.js | 5 +++++ src/reducers/rootReducer.js | 13 +++++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/reducers/filterReducer.js create mode 100644 src/reducers/queryReducer.js create mode 100644 src/reducers/resultReducer.js create mode 100644 src/reducers/rootReducer.js diff --git a/src/App.js b/src/App.js index 7e261ca..3a2b4b4 100755 --- a/src/App.js +++ b/src/App.js @@ -1,14 +1,17 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; +import { connect } from 'react-redux' class App extends Component { render() { + console.log(this.props.query) return (
logo

+ {this.props.query.hei} Edit src/App.js and save to reload.

( + { + query: state.query + } +) + + +export default connect(mapStateToProps)(App); diff --git a/src/index.js b/src/index.js index 0c5e75d..e278d03 100755 --- a/src/index.js +++ b/src/index.js @@ -3,8 +3,14 @@ import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; +import { createStore, applyMiddleware } from 'redux'; +import { Provider } from 'react-redux' +import thunk from 'redux-thunk' +import rootReducer from './reducers/rootReducer' -ReactDOM.render(, document.getElementById('root')); +const store = createStore(rootReducer, applyMiddleware(thunk)); + +ReactDOM.render(, document.getElementById('root')); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. diff --git a/src/reducers/filterReducer.js b/src/reducers/filterReducer.js new file mode 100644 index 0000000..d73f63c --- /dev/null +++ b/src/reducers/filterReducer.js @@ -0,0 +1,5 @@ +const filterReducer = ( state={}, action ) => { + return state +} + +export default filterReducer; \ No newline at end of file diff --git a/src/reducers/queryReducer.js b/src/reducers/queryReducer.js new file mode 100644 index 0000000..133661b --- /dev/null +++ b/src/reducers/queryReducer.js @@ -0,0 +1,5 @@ +const queryReducer = (state={hei:'hei'}, action) => { + return state +} + +export default queryReducer \ No newline at end of file diff --git a/src/reducers/resultReducer.js b/src/reducers/resultReducer.js new file mode 100644 index 0000000..3698b94 --- /dev/null +++ b/src/reducers/resultReducer.js @@ -0,0 +1,5 @@ +const resultReducer = (state={}, action) => { + return state +} + +export default resultReducer \ No newline at end of file diff --git a/src/reducers/rootReducer.js b/src/reducers/rootReducer.js new file mode 100644 index 0000000..a1d22d6 --- /dev/null +++ b/src/reducers/rootReducer.js @@ -0,0 +1,13 @@ +import { combineReducers } from 'redux' + +import queryReducer from './queryReducer' +import filterReducer from './filterReducer' +import resultReducer from './resultReducer' + +const rootReducer = combineReducers({ + query: queryReducer, + filter: filterReducer, + result: resultReducer +}) + +export default rootReducer \ No newline at end of file