Created
March 15, 2016 20:16
-
-
Save yamadapc/299e38ad7624d9b4f3b1 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import Perf from 'react-addons-perf'; | |
/** | |
* A floating button which starts/stops React's profiler. | |
*/ | |
export default class PerfMonitor extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {perfStarted: false}; | |
} | |
onClickStart = () => { | |
Perf.start(); | |
this.setState({perfStarted: true}); | |
}; | |
onClickStop = () => { | |
Perf.stop(); | |
Perf.printWasted(); | |
Perf.printInclusive(); | |
this.setState({perfStarted: false}); | |
}; | |
render() { | |
const msg = this.state.perfStarted ? 'Stop recording' : 'Start recording'; | |
const onClick = this.state.perfStarted ? this.onClickStop : this.onClickStart; | |
return ( | |
<div | |
style={{ | |
position: 'fixed', | |
bottom: 0, | |
right: 30, | |
}}> | |
<button onClick={onClick}>{msg}</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment