How do you add/remove to a redux store generated with normalizr?

前端 未结 5 1738
执笔经年
执笔经年 2021-01-30 00:02

Looking the examples from the README:

Given the \"bad\" structure:

[{
  id: 1,
  title: \'Some Article\',
  author: {
    id: 1,
    name: \'Dan\'
  }
},         


        
5条回答
  •  我在风中等你
    2021-01-30 00:52

    In your reducer, keep a copy of the un-normalized data. This way, you can do something like this (when adding a new object to an array in state):

    case ACTION:
      return {
        unNormalizedData: [...state.unNormalizedData, action.data],
        normalizedData: normalize([...state.unNormalizedData, action.data], normalizrSchema),
      }
    

    If you do not want to keep un-normalized data in your store, you can also use denormalize

提交回复
热议问题