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

208
Views
No se puede quitar al niño del enlace useRef

Tengo el siguiente useRef que contiene 4 hijos.
Estoy tratando de eliminar a un niño de aquí en función de una verificación if.

Pero obteniendo el error:

 typeError: myRef.current.removeChild is not a function.

Pero mirando las respuestas aquí, esto parece ser correcto. ¿Qué estoy haciendo mal?

¿Cómo eliminar el elemento secundario de un div en reaccionar usando useRef hook?

 //This is coming from another file. Just for reference. const myRef = React.useRef(); export const postData = ( myRef, token, id1, id2, ) => { myRef.current.children[0].value = token; myRef.current.children[1].value = id1; myRef.current.children[2].value = id2; [...myRef.current.children].forEach((child) => { if (!child.value) { // error on this line myRef.current.removeChild(child); } }); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

puede usar useEffect hook aquí, tal vez esto resuelva su problema.

 ... const myRef = useRef(null) useEffect(() => { myRef.current.children[0].value = token; myRef.current.children[1].value = id1; myRef.current.children[2].value = id2; [...myRef.current.children].forEach((child) => { if (!child.value) { myRef.current.removeChild(child); } }); }, [myRef.current, child.value]) return ( <div ref={myRef}> ... </div> ) ...
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!