无法在redux传奇中使用内部收益调用中的提取功能

问题描述

正在进行api调用,并且根据响应,我必须更新状态。 这就是我在做什么。

function* testEndpointConnectivity(action){
    const { testConnectivityUri,rowItem } = action.payload
    const res=  yield call( fetch(testConnectivityUri).then(response => {
        //something here
        })
    )
   
   yield put({type: SOME_ACTION});
   
}

但这不起作用。我得到了错误

 Error: call: argument fn is undefined

起初,我尝试将 yield put 放入响应的 catch then 中,但是stackoverflow告诉我使用屈服电话

在这里帮助。

解决方法

这是不正确的

如果您选中doc,则会看到它的第一个参数起作用,然后可以发送参数:

call(fn,... args)

因此,在您的示例中,正确的变体必须类似于:

function* testEndpointConnectivity(action) {
    const { testConnectivityUri,rowItem } = action.payload;
    const response = yield call(fetch,testConnectivityUri);
    // and in generator you can wait your answer,you dont need use .then
    console.log("response",response);

    yield put({ type: SOME_ACTION });

}

 // this error mean,first argument in call function must be fetch
 Error: call: argument fn is undefined