Created
September 29, 2018 12:05
-
-
Save Hydrock/5fa40ebc0c29430acf710b53d098b7a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Component, unstable_Profiler as Profiler } from "react"; | |
import { render } from "react-dom"; | |
class ComponentWithProfiling extends Component { | |
state = { | |
count: 0 | |
}; | |
logProfile = (id, phase, actualTime, baseTime, startTime, commitTime) => { | |
console.log(`${id}'s ${phase} phase:`); | |
console.log(`Actual time: ${actualTime}`); | |
console.log(`Base time: ${baseTime}`); | |
console.log(`Start time: ${startTime}`); | |
console.log(`Commit time: ${commitTime}`); | |
}; | |
go = direction => () => | |
this.setState(({ count }) => ({ | |
count: direction === "up" ? count + 1 : count - 1 | |
})); | |
render() { | |
return ( | |
<div> | |
<Profiler id="app" onRender={this.logProfile}> | |
<button onClick={this.go("up")}>☝️</button> | |
<div>The count is {this.state.count}</div> | |
<button onClick={this.go("down")}>👇</button> | |
</Profiler> | |
</div> | |
); | |
} | |
} | |
render(<ComponentWithProfiling />, document.getElementById("root")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment