【发布时间】:2021-08-17 01:38:10
【问题描述】:
我是 redux 的新手。
在我的场景中,我有一个输入字段,我使用这个输入字段来填充发布请求的正文:
Action ===> export const fetchSearchProducts = (search) => (dispatch) => {
fetch("/search", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(search),
})
.then((res) => res.json())
.then((data) => {
dispatch({ type: FETCH_SEARCH_ITEM, payload: data }); ===> this errors out saying Unhandled Rejection (TypeError): dispatch is not a function
// this console.log() actually returns the data im looking for
console.log(data)
});
};
这篇文章发送到 ExpressJS 服务器,在那里我使用“req.body.search”来填充 API 获取的 url 字段。 "url = https://example.nl?search=${req.body.search};"
直到这里它似乎工作......
现在我的问题是我试图在动作中使用 redux dispatch 填充状态.....但我不断收到这个错误:Unhandled Rejection (TypeError): dispatch is not a function
【问题讨论】:
标签: javascript reactjs express redux