Skip to content

Instantly share code, notes, and snippets.

@yamadapc
Created March 15, 2016 20:16
Show Gist options
  • Save yamadapc/299e38ad7624d9b4f3b1 to your computer and use it in GitHub Desktop.
Save yamadapc/299e38ad7624d9b4f3b1 to your computer and use it in GitHub Desktop.
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