Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get diff on rerender in React

Tags:

dom

reactjs

Is there a way to get the diff that React is getting of the DOM/Components? I can imagine trying to store changes as they happen so the user can 'undo' the changes [and am personally interested in the availability of the diff that is underlying the rerender (perhaps it would have the components that have changed?)].

EDIT: The undo feature was just an example. I am just interested in whether the above is possible to extract from React, since it is supposedly doing a diff of new and old tree.

like image 509
Cenoc Avatar asked Mar 10 '16 19:03

Cenoc


1 Answers

I'm trying to store changes as they happen so the user can 'undo' the changes

My proposition how to accomplish this:

React render result should be based only on states. If you give two times identical state, then DOM should be identical. Possibly child components should be stateless.

componentWillUpdate method is run after changes in props and states.

You can copy and save state after any state change.

And if user 'undo' changes then set old saved state as current state.

And DOM should be identical to previous state.

like image 134
Krzysztof Sztompka Avatar answered Sep 19 '22 19:09

Krzysztof Sztompka