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
class ReactRoot extends React.Component { | |
state = { | |
millis: Date.now(), | |
timezoneOffset: new Date().getTimezoneOffset(), | |
request: 0 | |
}; | |
componentDidMount() { | |
this.setState({ | |
request: requestAnimationFrame(this.tick) |
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
/* these methods and props are known to cause reflow and layout | |
see list from https://gist.github.com/paulirish/5d52fb081b3570c81e3a | |
*/ | |
const reflowLogger = function() { | |
// we don't want to redefine our properties | |
if (window.__reflow_log__) return; | |
window.__reflow_log__ = true; | |
const noop = () => {}; |
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
const withRemount = (Component, key) => (props) => { | |
const asKey = props[key]; | |
return <Component key={asKey} {...props} /> | |
} |
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
class App extends Component { | |
state = { | |
showCounter: false, | |
title: 'Whaaa! cool', | |
currentCount: 3 | |
} | |
componentDidUpdate(prevProps, prevState) { | |
const { showCounter, title, currentCount } = this.state; | |
const shouldUpdateCounter = |
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
class App extends Component { | |
componentDidMount(){ | |
window.ReactCounter.mount(); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> |
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
class App extends Component { | |
state = { | |
showCounter: false, | |
title: 'Whaaa! cool', | |
currentCount: 3 | |
} | |
// create refs so we can pass the element to mount and unmount | |
counterOneRef = React.createRef(); | |
counterTwoRef = React.createRef(); |
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
class App extends Component { | |
state = { showCounter: false, title: 'Whaaa! cool' } | |
componentDidUpdate(prevProps, prevState) { | |
const { showCounter, title } = this.state; | |
const shouldUpdateCounter = | |
prevState.showCounter !== showCounter || prevState.title !== title; | |
if (shouldUpdateCounter) { | |
if (showCounter) { | |
window.ReactCounter.mount({ title }); |
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
class App extends Component { | |
state = { showCounter: false } | |
componentDidUpdate(prevProps, prevState) { | |
const { showCounter } = this.state; | |
if (prevState.showCounter !== showCounter) { | |
if(showCounter){ | |
window.ReactCounter.mount(); | |
} else{ | |
window.ReactCounter.unmount(); |
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
class App extends Component { | |
state = { | |
showCounter: false, | |
title: 'Whaaa! cool', | |
currentCount: 3 | |
} | |
toggleCounter = () => this.setState(({ showCounter }) => ({ showCounter: !showCounter })); | |
onTitleChange = ({ target }) => this.setState({ title: target.value }); |
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
window.ReactCounter = { | |
mount: () => { | |
const el = document.getElementById('counter-app'); | |
ReactDOM.render(<Counter />, el); | |
}, | |
unmount: () => { | |
const el = document.getElementById('counter-app'); | |
ReactDOM.unmountComponentAtNode(el); | |
} | |
} |
OlderNewer