Skip to content

Commit 86d55e9

Browse files
committed
use redux-fetch-middleware and configure middleware
1 parent c3c9f16 commit 86d55e9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"react-dom": "^15.5.4",
6262
"react-redux": "^5.0.4",
6363
"redux": "^3.6.0",
64+
"redux-fetch-middleware": "^3.0.2",
6465
"redux-thunk": "^2.2.0",
6566
"rimraf": "~2.6.1",
6667
"semver": "~5.3.0",

src-react/store.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import { createStore, applyMiddleware } from 'redux';
22
import thunk from 'redux-thunk';
3+
import fetchMiddlewareCreator from 'redux-fetch-middleware';
34
import ungitApp from './reducers';
45

6+
const fetchMiddleware = fetchMiddlewareCreator({
7+
suffix: ['REQUEST', 'SUCCESS', 'FAILURE'],
8+
debug: process.env.NODE_ENV === 'development',
9+
fetchOptions: {
10+
headers: {
11+
'Accept': 'application/json',
12+
'Content-Type': 'application/json'
13+
}
14+
}
15+
});
16+
17+
const middlewares = [thunk, fetchMiddleware];
18+
519
const initialState = {
620
config: {
721
ungitConfig: null,
@@ -23,6 +37,6 @@ const initialState = {
2337
}
2438
};
2539

26-
const store = createStore(ungitApp, initialState, applyMiddleware(thunk));
40+
const store = createStore(ungitApp, initialState, applyMiddleware(...middlewares));
2741

2842
export default store;

0 commit comments

Comments
 (0)