16

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'})
}

1
  • The documentation example doesn't help us to help you. Please, share your relevant piece of code. Feb 3, 2019 at 16:20

1 Answer 1

33

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.