/** * Copyright (c) Meta Platforms, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import * as React from 'react'; function generateArray(size: number) { return Array.from({length: size}, () => Math.floor(Math.random() * size)); } const arr = generateArray(50000); export default function LargeSubtree(): React.Node { const [showList, setShowList] = React.useState(false); const toggleList = () => { const startTime = performance.now(); setShowList(!showList); // requestAnimationFrame should happen after render+commit is done window.requestAnimationFrame(() => { const afterRenderTime = performance.now(); console.log( `Time spent on ${showList ? 'unmounting' : 'mounting'} the subtree: ${ afterRenderTime - startTime }ms`, ); }); }; return (

Mount/Unmount a large subtree

Click the button to toggle the state. Open console for results.

); }