Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
How to get the number of rendered <ul> child elements using Observer API in react?

How to get the number of rendered ul child elements on when rendering element during map function, and on adding elements using mutation observer? , I am linking a code sandbox, please check the code before pressing add the add is causing the browser to freeze, in this particular case I want to console log 4 items when the app is rendered in the singular count, in other words, I want to keep track no how the list is expanding and how many elements are getting into it. the issue is the observer seems to be failing to run for some reason and if so it freezes the page. Please check the code before enabling the observable function it might crash your browser. the point here is to get the number of growing elements in real-time rather than after the list has been totally rendered due to some logic that needs to be implemented at a certain time rather than after the list is done rendering.

on first rendering log added 1 log added 2 log added 3 log added 4

after adding an item log added 5 and up

const onListMutation = useCallback(
    (mutationList) => {
      console.log(mutationList[0].target , `added${mutationList[0].target}`);
      setCount(mutationList[0].target.children.length);
    },
    [setCount]
  );

Codesandbox Example

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda