Skip to content

Instantly share code, notes, and snippets.

View marekpiechut's full-sized avatar
💭
👨‍💻Programming or playing 🎸

Marek Piechut marekpiechut

💭
👨‍💻Programming or playing 🎸
View GitHub Profile
const SlowComponent = React.memo(({ text, onClick }) => {
const arr = []
for (var i = 1000000 - 1; i >= 0; i--) {
arr.push(i)
}
return (
<div>
<div>I'm slow {text}</div>
<button onClick={onClick}/>
</div>
adb reverse tcp:8097 tcp:8097
<script src="http://localhost:8097"></script>
npm install -g react-devtools
react-devtools
import {
unstable_trace as trace,
unstable_wrap as wrap,
} from 'scheduler/tracing'
const useData = () => {
const [loading, setLoading] = useState(false)
const [data, setData] = useState(null)
const fetch = () => {
import {
unstable_trace as trace,
unstable_wrap as wrap,
} from 'scheduler/tracing'
<button
onClick={() =>
trace('Fetch data', performance.now(), () => {
setLoading(true)
fetchData()
import {
unstable_trace as trace,
} from 'scheduler/tracing'
<input
type="text"
value={name}
onChange={e => {
trace('Enter user name', performance.now(), () =>
onChange(e.target.value)
const ROUNDS = 100_000
const Benchmark = () => {
const [took, setTook] = useState()
const [round, setRound] = useState(1)
const start = useRef(performance.now())
useEffect(() => {
if (round < ROUNDS) {
setRound(round + 1)
} else {
# Using Yarn
yarn build --profile
# Using NPM
npm run build -- --profile
module.exports = {
//...
resolve: {
alias: {
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
}
}
};