Created
December 17, 2018 18:10
-
-
Save robskidmore/255bde4fb8987275974635c75a8f6a95 to your computer and use it in GitHub Desktop.
A performance profiling component for react -> https://www.telerik.com/blogs/profiling-react-components-with-the-user-timing-api
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
class MeasureRender extends React.Component { | |
constructor() { | |
super(); | |
this.mounted = false; | |
} | |
render() { | |
const { name } = this.props; | |
if (this.mounted) { | |
window.performance.mark(`${name}UpdateStart`); | |
} else { | |
window.performance.mark(`${name}MountStart`); | |
} | |
return this.props.children; | |
} | |
componentDidMount() { | |
const { name } = this.props; | |
this.mounted = true; | |
window.performance.mark(`${name}MountEnd`); | |
window.performance.measure(`${name}Mount`, `${name}MountStart`, `${name}MountEnd`); | |
} | |
componentDidUpdate() { | |
const { name } = this.props; | |
window.performance.mark(`${name}UpdateEnd`); | |
window.performance.measure(`${name}Update`, `${name}UpdateStart`, `${name}UpdateEnd`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment