Reactjs 不能使用关键字';等待&x27;在异步函数之外
目前我想对我的函数实现Redux,因此它将存储在initialstate中。为了做到这一点,我必须使用一个分派方法来调用函数内部的操作。因此,预期的结果是我可以使用Redux发送response.data.results,因此基于该结果,我可以在每个图像上添加一个like按钮。但这是一个稍后将要解决的问题,因为现在我想重构代码,以便函数将根据已提交的关键字或字母分派数据。但是console.log显示错误: 不能在异步函数外部使用关键字“wait”Reactjs 不能使用关键字';等待&x27;在异步函数之外,reactjs,redux,react-redux,Reactjs,Redux,React Redux,目前我想对我的函数实现Redux,因此它将存储在initialstate中。为了做到这一点,我必须使用一个分派方法来调用函数内部的操作。因此,预期的结果是我可以使用Redux发送response.data.results,因此基于该结果,我可以在每个图像上添加一个like按钮。但这是一个稍后将要解决的问题,因为现在我想重构代码,以便函数将根据已提交的关键字或字母分派数据。但是console.log显示错误: 不能在异步函数外部使用关键字“wait” onSearchSubmit=async t
onSearchSubmit=async term=>{
返回(发送)=>{
const response=wait unsplash.get(“/search/photos”{
参数:{query:term},
//使用“取消闪烁”上的路径进行图像搜索
});
调度(获取图像(response.data.results));
//this.setState({images:response.data.results});
}
}
render(){
报税表(
{/* */}
);
}
您将返回一个非异步函数并在其中调用wait。尝试使其异步:
return async (dispatch) => {
const response = await unsplash.get('/search/photos', {
params:{ query: term },
您的错误所指的
wait
是在匿名lambda函数(dispatch)=>{…
中,而不是onSearchSubmit
。使lambda异步,一切都应该正常
return async (dispatch) => {
const response = await unsplash.get('/search/photos', {
params:{ query: term },