React check if form is dirty

React check if form is dirty


Create a startpoint and put that in your state.
const startState = {
    a: true,
b: false
}

Change your state
this.state = this.startState;
Compare it to startState
this.state = this.startState;

Full Code:
const startState = 
{ 
a: true,
b: false
} this.state = this.startState; addAction()
{
if( JSON.stringify(startState) !== JSON.stringify(this.state)
{ /* Some code goes here */}
 }


Thank you