From be0276262007ac7bf7886781fc2a3bbe523773e5 Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Tue, 16 Jul 2019 01:24:17 +0530 Subject: [PATCH] App: setState migration --- src/components/app.jsx | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/app.jsx b/src/components/app.jsx index 3771f63..cd5dfd5 100644 --- a/src/components/app.jsx +++ b/src/components/app.jsx @@ -281,19 +281,25 @@ export default class App extends Component { } incrementUnsavedChanges() { - this.setState({ unsavedEditCount: this.state.unsavedEditCount + 1 }); + this.setState(prevState => { + const newCount = prevState.unsavedEditCount + 1; - if ( - this.state.unsavedEditCount % UNSAVED_WARNING_COUNT === 0 && - this.state.unsavedEditCount >= UNSAVED_WARNING_COUNT - ) { - window.saveBtn.classList.add('animated'); - window.saveBtn.classList.add('wobble'); - window.saveBtn.addEventListener('animationend', () => { - window.saveBtn.classList.remove('animated'); - window.saveBtn.classList.remove('wobble'); - }); - } + console.log('checking on ', newCount); + + if ( + newCount % UNSAVED_WARNING_COUNT === 0 && + newCount >= UNSAVED_WARNING_COUNT + ) { + window.saveBtn.classList.add('animated'); + window.saveBtn.classList.add('wobble'); + window.saveBtn.addEventListener('animationend', () => { + window.saveBtn.classList.remove('animated'); + window.saveBtn.classList.remove('wobble'); + }); + } + + return { unsavedEditCount: newCount }; + }); } updateProfileUi() {