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

198
Views
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
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!