小编Min*_*ang的帖子

关于不带中间件的Redux异步(redux-thunk,redux-saga ...)

一些动作具有异步功能,例如提取。但是,我不想使用像redux-thunk或redux-saga这样的中间件。因此,我不愿意使用此代码。

/* actions */

...

export const fetchRequest = ({category, query, dispatch}) => ({
    type: actionTypes.FETCH_REQUEST,
    promise:
        fetch(`${API_URL}${category}?${query}`, {headers: headers})
        .then(response => response.json())
        .then(data => dispatch(fetchRecieve(data))),
})

export const fetchRecieve = data => ({
    type: actionTypes.FETCH_RECIEVE,
    data,
})

...

/* In x.jsx */
...

const mapDispatchToProps = dispatch => ({
onClick: (category, query) => dispatch(fetchRequest({category, query, dispatch}))
})

...
Run Code Online (Sandbox Code Playgroud)

Redux范式是否违反了此代码?

javascript reactjs redux redux-thunk redux-saga

4
推荐指数
1
解决办法
263
查看次数

标签 统计

javascript ×1

reactjs ×1

redux ×1

redux-saga ×1

redux-thunk ×1