Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class extends React.Component {
private canRender: boolean = false;
private latestData: any;
constructor(props) {
super(props);
let nJobs = 0;
let lastRenderTime: number;
props.someObservableThing.listen(data => {
nJobs++;
this.latestData = data;
if (this.canRender) {
const now = performance.now();
this.canRender = false;
this.setState({
data: this.latestData,
jobsPerRender: nJobs,
fps: (lastRenderTime === undefined) ? 0 : 1000 / (now - lastRenderTime)
});
nJobs = 0;
lastRenderTime = now;
}
});
this.state = {};
}
/* Lifecycle */
componentDidMount() {
this.canRender = true;
}
componentDidUpdate() {
this.canRender = true;
}
render() {
outputStats(this.state);
return this.state.data === undefined ? null : <View {...this.state.data} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.