Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Merge action raise 'Actions must be plain objects'. #890

Closed
marcosschroh opened this issue Jul 27, 2017 · 7 comments
Closed

Merge action raise 'Actions must be plain objects'. #890

marcosschroh opened this issue Jul 27, 2017 · 7 comments
Labels

Comments

@marcosschroh
Copy link

The Problem

Can't merge an object into the model

Steps to Reproduce

  1. I have a modelReducer with some fields
  2. I have an object, just with a couple of fields.
  3. I dispatch the merge action and raise the error.

I am using sagas. I have used other actions like load, change, reset, resetValidity and setValidity and they are working well.

For example:

//working
function * resetValidityReactReduxForm(action) {
  // model should be the model: @str
  yield put(actions.resetValidity(action.payload.model));
}

//working
function * loadModelReactReduxForm(action) {
  // model should be the model: @str
  // model should be the next value: @object
  yield put(actions.load(action.payload.model, action.payload.value));
}

//working
function * changeModelReactReduxForm(action) {
  // model should be the model: @str
  // model should be the next value: @object
  yield put(actions.change(action.payload.model, action.payload.value));
}

// not working, raise the error
function * mergeReduxForm(action) {
  // model should be the model: @str
  // model should be the next object to merge: @obj
  yield put(actions.merge(action.payload.model, action.payload.obj));
}

Expected Behavior

Get the formReducer with the old values, and the new values after merge

Actual Behavior

Get the error: Actions must be plain objects. Use custom middleware for async actions.

@davidkpiano
Copy link
Owner

Are you also using redux-thunk? Those actions only work with redux-thunk (which, yes, does work with redux-saga as well)

@marcosschroh
Copy link
Author

I am using redux-saga 0.14.8. Is weird because is working with other actions.

@davidkpiano
Copy link
Owner

By other actions, you mean with other thunk actions?

@marcosschroh
Copy link
Author

I mean actions.change, actions.load, etc.

@davidkpiano
Copy link
Owner

Those aren't thunk actions, so they will work without redux-thunk. Make sure you're using redux-thunk in order to use actions.merge.

import thunk from 'redux-thunk';
import createSagaMiddleware from 'redux-saga';

const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware, thunk];

// ... in creating your store:
/* ... */ applyMiddleware(...middlewares)

@marcosschroh
Copy link
Author

thanks @davidkpiano !! awesome.

@lydia-schow
Copy link
Contributor

lydia-schow commented Aug 7, 2018

@davidkpiano I get this same issue while trying to use LocalForms. Unfortunately, I don't see any way to use thunks with LocalForms. I'm intentionally NOT using my own redux store.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants