Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
¿Cómo comparar el componente de reacción?

Quiero comparar la representación de un componente de React para poder realizar mejoras incrementales.

Se me ocurrió este prototipo para usar con reaccionar v18:

 import { useEffect, } from 'react'; import { createRoot, } from 'react-dom'; import { JsonView, } from '../components/JsonView'; const render = (root) => { return new Promise((resolve) => { root.render(<div ref={() => { resolve(undefined); }} > <JsonView activePath={null} entries={{foo: 'bar'}} expanded highlights={[]} onActivePathChange={() => {}} /> </div>); }); }; const TestPage = () => { useEffect(() => { const sandbox = document.createElement('div'); document.body.appendChild(sandbox); const root = createRoot(sandbox); (async () => { const startTime = Date.now(); const runTime = 1_000; let renderCount = 0; while (Date.now() - startTime < runTime) { await render(root); renderCount++; } console.log('done', renderCount); })(); return () => { document.body.removeChild(sandbox); }; }, []); return <div />; }; export default TestPage;
  • JsonView es el componente que quiero comparar.
  • ref se usa para identificar cuándo se crea div .
  • startTime / runTime se utilizan para limitar el tiempo de ejecución del conjunto de pruebas.

Esto funciona bien: obtengo resultados de referencia consistentes y los cambios en el componente muestran una mejora/degradación del rendimiento.

Sin embargo, me preguntaba si esta es la forma correcta de comparar un componente de React o si debería usar otro mecanismo.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!