Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The delay functionality from redux saga is not working

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'})
}
like image 773
Tzvetlin Velev Avatar asked Feb 03 '19 03:02

Tzvetlin Velev


People also ask

Is Redux saga still maintained?

Such a powerful & elegant tool as Redux-Saga, a Redux side effect manager, is said to be deprecated, and no longer being maintained, starting from Jan 27, 2021.

What is takeEvery in Redux saga?

Calling them spawns a saga on each action dispatched to the Store that matches pattern. takeEvery: The most common takeEvery function is very similar to redux-thunk in its behaviour and methodology. It's basically a wrapper for yield take of a pattern or channel and yield fork .

How do Redux sagas work?

Redux Saga is a middleware library used to allow a Redux store to interact with resources outside of itself asynchronously. This includes making HTTP requests to external services, accessing browser storage, and executing I/O operations. These operations are also known as side effects.


1 Answers

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

like image 89
Martin Kadlec Avatar answered Oct 18 '22 04:10

Martin Kadlec