Reputation: 2027
Im trying to use the delay functionality but I get an error that delay is not a function.
Straight from the docs:
import { race, call, put, delay } from 'redux-saga/effects'
function* fetchPostsWithTimeout() {
const {posts, timeout} = yield race({
posts: call(fetchApi, '/posts'),
timeout: delay(1000)
})
if (posts)
yield put({type: 'POSTS_RECEIVED', posts})
else
yield put({type: 'TIMEOUT_ERROR'})
}
Upvotes: 16
Views: 9645
Reputation: 4975
I suspect the reason for this is because the docs were recently updated for redux-saga v1.0.0
. This is important because previously (in 0.x versions you are probably using) it wasn't effect but just a helper.
In the 0.x version you should import it as:
import {delay} from 'redux-saga'
This delay function will return a promise.
In the 1.0.0 version you can use it as mentioned in the docs.
import {delay} from 'redux-saga/effects'
This delay is an effect creator and will return an effect object.
For more info about the v1 release see https://github.com/redux-saga/redux-saga/releases/tag/v1.0.0
Upvotes: 33