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

251
Views
Cuente el número de niños en el componente de reacción recursiva

Estoy trabajando en un sistema de comentarios y utilicé un enfoque recursivo para mostrar los comentarios de padres e hijos. Cuando elimino un niño, quiero actualizar el recuento de comentarios de niños para su padre.

//datos json data = [{ nombre: 'Padre1', childComments: [{ nombre: 'Child1', text:'child comment1' }, { name: 'Child2', text:'child comment2' }] },{ nombre: 'Parent2', childComments: [{ name: 'Child1', text:'child comment1' }, { name: 'Child2', text:'child comment2' }] }]

 const Comment = ({ item }) => { const childComment = item //delete child element and update the parent count const deleteChildComment =(item) => { } return childComment && ( <> {name} Children count : {childComments.length} <Button className={styles.replies} onClick={() => { setNewCommentAdded(false) deleteChildComment(childComment) }} > Delete This comment </Button> {childComments && items.map((item) => ( <Comment item={item} /> ))} </> ) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Contar a los niños sería una mala idea y complicaría demasiado las cosas. Simplemente use los datos que usa para generar el componente de comentarios.

Como regla general, siempre haga que una interfaz de usuario represente datos. No intente derivar datos de su diseño de interfaz de usuario.

p.ej

 commentList.map((comment) => (<Comment childCount={comment.children.length}));
about 4 years ago · Juan Pablo Isaza Report
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!