/
ashipov
/
react
Обзор
Документация
Войти
/
ashipov
/
react
Код
Запросы
0
Задачи 2.0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
packages/react-devtools-shell/src/app/TraceUpdatesTest/index.js
87 строк
2 KB
YongSeok Jang (장용석)
[DevTools] Use Popover API for TraceUpdates highlighting (#32614)
07 май 2025, 17:48
Не верифицирован
07 май 2025, 17:48
53c9f81
Код
Авторство
О чём код?
/** * 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. * * @flow */ import * as React from 'react'; import {useRef, useState} from 'react'; const Counter = () => { const [count, setCount] = useState(0); return ( <div> <h3>Count: {count}</h3> <button onClick={() => setCount(c => c + 1)}>Increment</button> </div> ); }; function DialogComponent() { const dialogRef = useRef(null); const openDialog = () => { if (dialogRef.current) { dialogRef.current.showModal(); } }; const closeDialog = () => { if (dialogRef.current) { dialogRef.current.close(); } }; return ( <div style={{margin: '10px 0'}}> <button onClick={openDialog}>Open Dialog</button> <dialog ref={dialogRef} style={{padding: '20px'}}> <h3>Dialog Content</h3> <Counter /> <button onClick={closeDialog}>Close</button> </dialog> </div> ); } function RegularComponent() { return ( <div style={{margin: '10px 0'}}> <h3>Regular Component</h3> <Counter /> </div> ); } export default function TraceUpdatesTest(): React.Node { return ( <div> <h2>TraceUpdates Test</h2> <div style={{marginBottom: '20px'}}> <h3>Standard Component</h3> <RegularComponent /> </div> <div style={{marginBottom: '20px'}}> <h3>Dialog Component (top-layer element)</h3> <DialogComponent /> </div> <div style={{marginTop: '20px', padding: '10px', border: '1px solid #ddd'}}> <h3>How to Test:</h3> <ol> <li>Open DevTools Components panel</li> <li>Enable "Highlight updates when components render" in settings</li> <li>Click increment buttons and observe highlights</li> <li>Open the dialog and test increments there as well</li> </ol> </div> </div> ); }