Last active
May 1, 2018 16:54
-
-
Save ramubotsplash/48ee29effcfe05e6847517ee43b2cd35 to your computer and use it in GitHub Desktop.
ReactJs to Pure Js with setState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FROM: ReactJs | |
activateChat() { | |
this.setState({ isChatActive: true }); | |
} | |
// TO: Js | |
setState = (updatedState: Object) => { | |
this.state = {...this.state, ...updatedState}; | |
setTimeout(() => this.updateClasses()); | |
} | |
updateClasses = () => { | |
const bubbleEl = document.getElementById(CHAT_BUBBlE_ID); | |
if (bubbleEl) { | |
const bubbleCssClasses = this.getBubbleElementClasses(); | |
const bubbleCssStyles = this.getBubbleElementStyles(); | |
bubbleEl.setAttribute('class', bubbleCssClasses); | |
Object.assign(bubbleEl.style, bubbleCssStyles); | |
} | |
... | |
this.updateChildClasses(); | |
... | |
} | |
activateChat() { | |
this.setState({ isChatActive: true }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment