mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
- `react-devtools-shell` is only used for e2e tests - Based on the React version we testing against, we will show/hide roots using legacy render
41 lines
927 B
JavaScript
41 lines
927 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import * as React from 'react';
|
|
import {useLayoutEffect, useRef, useState} from 'react';
|
|
import {createRoot} from 'react-dom/client';
|
|
|
|
function createContainer() {
|
|
const container = document.createElement('div');
|
|
|
|
((document.body: any): HTMLBodyElement).appendChild(container);
|
|
|
|
return container;
|
|
}
|
|
|
|
function EffectWithState() {
|
|
const [didMount, setDidMount] = useState(0);
|
|
|
|
const renderCountRef = useRef(0);
|
|
renderCountRef.current++;
|
|
|
|
useLayoutEffect(() => {
|
|
if (!didMount) {
|
|
setDidMount(true);
|
|
}
|
|
}, [didMount]);
|
|
|
|
return (
|
|
<ul>
|
|
<li>Rendered {renderCountRef.current} times</li>
|
|
{didMount && <li>Mounted!</li>}
|
|
</ul>
|
|
);
|
|
}
|
|
|
|
createRoot(createContainer()).render(<EffectWithState />);
|