Skip to content

Commit

Permalink
Redux setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cficht committed May 20, 2020
1 parent 9ae1df4 commit a31745c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"redux": "^4.0.5"
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.9.6",
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from 'react';
import { render } from 'react-dom';
import App from './components/App/App';
import { Provider } from 'react-redux';
import store from './store';

render(
<App />,
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
6 changes: 6 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { combineReducers } from 'redux';
import restaurants from './restaurantReducer';

export default combineReducers({
restaurants: restaurants
});
10 changes: 10 additions & 0 deletions src/reducers/restaurantReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const initialState = {
restaurants: []
};

export default function reducer(state = initialState, action) {
switch(action.type) {
default:
return state;
}
}
12 changes: 12 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createStore, compose, applyMiddleware } from 'redux';
import reducers from './reducers';
import thunk from 'redux-thunk';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

export default createStore(
reducers,
composeEnhancers(
applyMiddleware(thunk)
)
);

0 comments on commit a31745c

Please sign in to comment.