我想在 saga 中引入延迟(使用 redux-saga)。
我该怎么做?
如果redux-saga提供了API,我也很想知道如何手动实现。
function* save({ payload }) {
yield put(pending());
// I want to simply wait (non-blocking) here for say 2 seconds
yield put(complete());
}
最佳答案
Redux-sagas 有 a special effect为此:
delay(ms, [val])
Returns a Promise that will resolve after ms milliseconds with val.
例子:
import { delay, call } from 'redux-saga/effects'
function* someSaga(input) {
yield put(someAction())
yield delay(500)
yield put(anotherAction())
}
关于javascript - 在 redux-saga 中等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47634803/