Saman Mohamadi
Saman Mohamadi

Reputation: 4672

react-admin, custom reducer to manipulate data inside state.admin

I want to inject a custom reducer into react-admin to manipulate data inside state.admin.

There is a section in doc for adding a custom reducer but this reducer can handle its own namespace.

How can I access and change data inside state.admin?

Upvotes: 0

Views: 970

Answers (1)

François Zaninotto
François Zaninotto

Reputation: 7355

You can't update data in another Redux reducer if the store was created using combineReducer() - which is the case in react-admin. That's a design decision by Redux.

In your case, you have 2 possibilities:

  • Add a middleware (or a custom saga) that will redispatch an action based on your action. That will allow you to dispatch react-admin actions (like CRUD_DELETE_SUCCESS) that actually update the store. That way, you'll be able to (indirectly) update any part of the store.
  • add a reducer that listens to react-admin actions and stores the related data. that means you'll copy the react-admin reducer data in another custom reducer.

Upvotes: 4

Related Questions