Skip to content

Commit 91495d8

Browse files
committed
load data via utils in store
1 parent fe66c27 commit 91495d8

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/store/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { createStore, thunk, action } from 'easy-peasy';
2-
import fetch from 'unfetch';
2+
import { fetchJson } from 'utils/data-utils';
33

44
const model = {
55
app: {
66
data: null,
77
dataLoading: false,
88
loadData: thunk(async (actions) => {
9-
try {
10-
actions.loadDataStart();
11-
const response = await fetch('static/data/data.json');
12-
const data = await response.json();
9+
actions.loadDataStart();
10+
const data = await fetchJson('static/data/data.json');
11+
if (data) {
1312
actions.loadDataSuccess(data);
14-
} catch (_) {
15-
actions.loadDataFail(_);
13+
} else {
14+
actions.loadDataFail();
1615
}
1716
}),
1817
loadDataStart: action((state) => {

0 commit comments

Comments
 (0)