In Redux, is it necessary to do deep copy

后端 未结 3 1820
逝去的感伤
逝去的感伤 2020-12-30 20:09

The below object is action.data has a nested object address

{
    name: \'Ben\',
    address: {
        country: \'Australia\',
            


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 21:16

    The "correct" way to handle updates of nested data is with multiple shallow copies, one for each level of nesting. It's also certainly okay to create a new object that just replaces one field completely, per your first example.

    See the Redux docs section on Immutable Update Patterns for some info on how to properly do immutable updates, and also the Redux FAQ entry regarding deep cloning.

提交回复
热议问题