The delay functionality from redux saga is not working
Asked Answered
R

1

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'})
}
Rockling answered 3/2, 2019 at 3:32 Comment(1)
The documentation example doesn't help us to help you. Please, share your relevant piece of code.Defluxion
U
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

Unity answered 3/2, 2019 at 23:7 Comment(1)
ill give it a shot.Rockling

© 2022 - 2024 — McMap. All rights reserved.