刷新浏览器时,saga可以执行该功能吗?

时间:2018-07-07 05:53:17

标签: reactjs react-redux redux-saga react-component

'我试图在刷新浏览器时遵循执行过程,但我发现saga不执行fetchOrders函数。

你有个主意吗?'

反应成分:

componentWillMount(){
    this.props.dispatch({type:'FETCH_ORDERS'})
}

动作文件:

export function* fetchOrders(){
    try {
        let orders = JSON.parse(localStorage.getItem('orders')) || [];
        yield put({type: 'FETCH_ORDERS_SUCCESS', payload: orders})

    } catch (error) {
        yield put({type: 'FETCH_ORDERS_ERROR', payload: error})

   }
}



export default function* ordersSaga() {
    yield all([
        takeEvery('EDIT_ORDER', editOrder),
        takeEvery('ADD_ORDER', addOrder),
        takeEvery('FETCH_ORDERS',fetchOrders)
    ])
}

0 个答案:

没有答案