What are disadvantages to using immutable state in React?

前端 未结 3 1006
萌比男神i
萌比男神i 2020-12-08 20:42

I have built my first React application with stateful stores the \"normal\" way, and now I am looking into using an immutable global state like used in the Este starterkit.<

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 20:52

    One advantage of passing data through props is that you can utilize shouldComponentUpdate for more performant updates. If you assume data always comes from the parent (e.g. via props), you can effectively prevent a large portion of your component tree from having to rerender. Immutable values make this very nice as you can do reference equality checks in shouldComponentUpdate relatively high in your component hierarchy.

    The only other disadvantage I've found when using immutable data with React is that the React developer tools don't work super well with them (they show you the immutable values' underlying data structure instead of a JS-friendly value).

提交回复
热议问题