Isn't Redux just glorified global state?

后端 未结 1 1584
执念已碎
执念已碎 2021-01-30 15:52

So I started learning React a week ago and I inevitably got to the problem of state and how components are supposed to communicate with the rest of the app. I searched around an

相关标签:
1条回答
  • 2021-01-30 16:09

    Isn't Redux just glorified global state?

    Of course it is. But the same holds for every database you have ever used. It is better to treat Redux as an in-memory database - which your components can reactively depend upon.

    Immutability enables checking if any sub-tree has been altered very efficient because it simplifies down to an identity check.

    Yes, your implementation is efficient, but the entire virtual dom will have to be re-rendered each time the tree is manipulated somehow.

    If you are using React, it will eventually do a diff against the actual dom and perform minimal batch-optimized manipulations, but the full top-down re-rendering is still inefficient.

    For an immutable tree, stateless components just have to check if the subtree(s) it depends on, differ in identities compared to previous value(s), and if so - the rendering can be avoided entirely.

    0 讨论(0)
提交回复
热议问题