Commit 1e315ca3 authored by afc163's avatar afc163

Fix setState on unmounted component, close #338

parent 753dc958
...@@ -14,10 +14,15 @@ export default { ...@@ -14,10 +14,15 @@ export default {
salesTypeDataOnline: [], salesTypeDataOnline: [],
salesTypeDataOffline: [], salesTypeDataOffline: [],
radarData: [], radarData: [],
loading: false,
}, },
effects: { effects: {
*fetch(_, { call, put }) { *fetch(_, { call, put }) {
yield put({
type: 'changeLoading',
payload: true,
});
const response = yield call(fakeChartData); const response = yield call(fakeChartData);
yield put({ yield put({
type: 'save', type: 'save',
...@@ -40,12 +45,7 @@ export default { ...@@ -40,12 +45,7 @@ export default {
return { return {
...state, ...state,
...payload, ...payload,
}; loading: false,
},
setter(state, { payload }) {
return {
...state,
...payload,
}; };
}, },
clear() { clear() {
...@@ -62,5 +62,11 @@ export default { ...@@ -62,5 +62,11 @@ export default {
radarData: [], radarData: [],
}; };
}, },
changeLoading(state, { payload }) {
return {
...state,
loading: payload,
};
},
}, },
}; };
...@@ -27,7 +27,6 @@ for (let i = 0; i < 7; i += 1) { ...@@ -27,7 +27,6 @@ for (let i = 0; i < 7; i += 1) {
})) }))
export default class Analysis extends Component { export default class Analysis extends Component {
state = { state = {
loading: true,
salesType: 'all', salesType: 'all',
currentTabKey: '', currentTabKey: '',
rangePickerValue: [], rangePickerValue: [],
...@@ -36,7 +35,7 @@ export default class Analysis extends Component { ...@@ -36,7 +35,7 @@ export default class Analysis extends Component {
componentDidMount() { componentDidMount() {
this.props.dispatch({ this.props.dispatch({
type: 'chart/fetch', type: 'chart/fetch',
}).then(() => this.setState({ loading: false })); });
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -90,7 +89,7 @@ export default class Analysis extends Component { ...@@ -90,7 +89,7 @@ export default class Analysis extends Component {
} }
render() { render() {
const { rangePickerValue, salesType, currentTabKey, loading } = this.state; const { rangePickerValue, salesType, currentTabKey } = this.state;
const { chart } = this.props; const { chart } = this.props;
const { const {
visitData, visitData,
...@@ -102,6 +101,7 @@ export default class Analysis extends Component { ...@@ -102,6 +101,7 @@ export default class Analysis extends Component {
salesTypeData, salesTypeData,
salesTypeDataOnline, salesTypeDataOnline,
salesTypeDataOffline, salesTypeDataOffline,
loading,
} = chart; } = chart;
const salesPieData = salesType === 'all' ? const salesPieData = salesType === 'all' ?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment