0

React/react-dom 是否有能力让用户手动比较两个 dom,获取 diff,并手动将 diff 应用到 dom?

就像现在发生的那样,似乎差异和修补的过程是在内部完成的,但我希望单独进行。

4

1 回答 1

1

No, there is no way currently to do this. Not really sure why you would need React if you were to do reconciliation on your own. As you mention, this is done internally. You could probably fork react and change the way it does diffs, or maybe even expose an external API to let developers do their own diffs if they want.

React is pretty good at what it does, and it unlikely you will do better. See the Reconciliation and Advanced Performance sections for more on how React does diffs.

Now, what you can do within a React component is specify a shouldComponentUpdate method and tell each component if it should update (and thus possibly have to reconcile) the DOM. This is actually recommended to improve performance if your components are pure based on props/state.

于 2016-02-04T00:16:49.173 回答