Redux: fat action creators vs fat reducers for data `sanitization`?

Viewed 97

I am using data from a backend server (which I don't have control over), and the data is not reliable. For example, it's missing values for some fields, and sometimes has a wrong/unacceptable value for a certain field.

I need to sanitize this data on a frontend to make sure that the frontend app receives data of good quality and in an expected format.

Where is the best place to place such a logic to parse & convert data from the backend?

  • action creators - After fetching data from the backend using fetch API, I can sanitize data and dispatch an action with sanitized data.

  • reducers - After receiving an unsanitized data, reducers can parse them before saving them into a store.

Which one is more acceptable - fat action creators or `fat reducers'?

1 Answers

While the general recommendation is to put as much logic as possible into reducers, in this case I would opt for doing the "sanitizing" part in the thunk as it kinda feels like still being a "part of the fetch" - but then do the "select what you really need" part (if only a part of the result is required) probably in the reducer.

Related