Skip to content

Instantly share code, notes, and snippets.

@marekpiechut
Created June 22, 2021 10:53
Show Gist options
  • Select an option

  • Save marekpiechut/e749b71401dd1bc09c547f90fe8a2424 to your computer and use it in GitHub Desktop.

Select an option

Save marekpiechut/e749b71401dd1bc09c547f90fe8a2424 to your computer and use it in GitHub Desktop.
React-profiler
import { useState } from 'react'
const SlowComponent = ({ noSlowdown }) => {
const arr = []
if (!noSlowdown) {
for (var i = 1000000 - 1; i >= 0; i--) {
arr.push(i)
}
}
return <div>I'm slooooooow</div>
}
const FastComponent = () => {
return <div>I'm fassssst....</div>
}
function App() {
const [dummy, setDummy] = useState()
return (
<div className="App">
<SlowComponent noSlowdown={dummy % 2} />
<FastComponent />
<button onClick={() => setDummy(Date.now())}>Render!</button>
</div>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment