小编LGi*_*nez的帖子

从 redux 工具包导出额外的减速器

我不久前制作了一个待办事项列表,作为练习 React 和 Redux 的一种方式。现在我正在尝试使用 redux 工具包重写它,但在操作创建者方面遇到了一些麻烦。

这是旧的动作创建者:

export const changeDescription = (event) => ({
    type: 'DESCRIPTION_CHANGED',
    payload: event.target.value })

export const search = () => {
    return (dispatch, getState) => {
        const description = getState().todo.description
        const search = description ? `&description__regex=/${description}/` : ''
        axios.get(`${URL}?sort=-createdAt${search}`)
            .then(resp => dispatch({ type: 'TODO_SEARCHED', payload: resp.data }))
    } }

export const add = (description) => {
    return dispatch => {
        axios.post(URL, { description })
            .then(() => dispatch(clear()))
            .then(() => dispatch(search()))
    } }

export const …
Run Code Online (Sandbox Code Playgroud)

reactjs redux redux-thunk redux-toolkit

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

标签 统计

reactjs ×1

redux ×1

redux-thunk ×1

redux-toolkit ×1