reduxreselectnormalizr

Transform entity / normalized response


I wonder where is a good place to transform a response entity(ies) before it is set in my Redux state.

Example

Questions

  1. Do I compute this new attribute in a getChatMessages selector (reselect)?
  2. Do I compute this new attribute before I set the normalized response in my state? – Hence my question "Transform"
  3. Do I just calculate it in my Component, but this (simple) logic is not shared and duplicated all over the place...
  4. Do I send the unread attribute from the server...

Notes


Solution

  • Normalizr provides the processStrategy option:

    Strategy to use when pre-processing the entity. Use this method to add extra data, defaults, and/or completely change the entity before normalization is complete.