0

我在谷歌上搜索了 Redux thunk,我大致了解了它的用途以及如何制作它,当我即将开始制作它时,我才意识到我可能已经制作了一个。我说可能是因为当我使用 asp.net 核心作为后端创建 React 应用程序时,我的代码基于 Visual Studio 制作的样板代码。有问题的代码:

editLecture: (lecture) => (dispatch) => {
        dispatch({ type: EDITING_LECTURE, payload: lecture })
        const url = `api/lecture/${lecture.topicID}`
        const response = fetch(url, {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(lecture)
        }).then(res =>
            res.json()
        ).then(json =>
            dispatch({ type: EDITED_LECTURE, payload: json })
        )
    }

所以,是的,这是一个thunk吗?PS:我是一个 JS/React/Redux 菜鸟,所以如果这是一个明显的答案,我很抱歉..

4

0 回答 0