Skip to content

Instantly share code, notes, and snippets.

@romelperez
Last active April 7, 2021 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romelperez/08d49cbc07a05c67895b3cc1d394b1bc to your computer and use it in GitHub Desktop.
Save romelperez/08d49cbc07a05c67895b3cc1d394b1bc to your computer and use it in GitHub Desktop.
Simple React profiler for mount phase for production environment.
import React, { useEffect, useState } from 'react';
import { render } from 'react-dom';
const ProductionProfiler = ({ children }) => {
const [mount, setMount] = useState(false);
useEffect(() => {
if (!mount) {
console.time('profile');
setMount(true);
}
else {
console.timeEnd('profile');
}
}, [mount]);
return mount ? children : null;
};
const Item = () => {
return <div className='item'>Hello</div>;
};
render(
<ProductionProfiler>
{Array(1000).fill(0).map((_, index) => (
<Item key={index} />
))}
</ProductionProfiler>,
document.querySelector('#root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment