Parthiban
Parthiban

Reputation: 31

"You can't put (a.k.a. dispatch from saga) frozen actions" - Redux Saga

This is my first stackoverflow questions please excuse if there is any mistake.

I am a beginner to react, redux and saga. I am trying to dispatch an action which will be handled by saga and then dispatch another action from within saga. While I do this I get this below error message :

"You can't put (a.k.a. dispatch from saga) frozen actions. We have to define a special non-enumerable property on those actions for scheduling purposes. Otherwise you wouldn't be able to communicate properly between sagas & other subscribers (action ordering would become far less predictable). If you are using redux and you care about this behaviour (frozen actions), then you might want to switch to freezing actions in a middleware rather than in action creator. Example implementation:

const freezeActions = store => next => action => next(Object.freeze(action))"

I haven't explicitly frozen my actions anywhere. I am just calling a function which returns an action object. I dont understand why saga complains that its frozen object.

I have reproduced my error in this sandbox : https://codesandbox.io/s/elastic-zhukovsky-ntmfn

Upvotes: 2

Views: 1377

Answers (1)

Parthiban
Parthiban

Reputation: 31

So solution was very simple. When I was trying to import action creator function I was not importing within {}. Action creator was not a default export from where it was defined.

import { setSnackbar } from "../../ducks/snackbar"; //---> senSnackbar should be imported within brackets.
//import setSnackbar from "../../ducks/snackbar"; //->dont do this
import { call, put } from "redux-saga/effects";

export function* handleCheckCoin(action) {
  try {
    let strSymbol = action.payload;
    console.log("Symbol : " + JSON.stringify(strSymbol));
    ///send out a api request to check Crypto Symbol is valid
    yield put(setSnackbar(true, "success", "message"));
  } catch (error) {
    console.log("error while launching set snack bar action : " + error);
  }
}

Upvotes: 1

Related Questions