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

152
Views
Cambiar el estado del componente principal en el componente secundario

Quiero cambiar un valor en el componente principal cambiando el estado en el componente secundario que pasan los accesorios.

 // This is the parent component const [showEdit, setShowEdit] = useState(false); <EditApplicationSettings appSettings={appSettings} changeState={(showEdit) => setShowEdit(showEdit)} /> // This is the child component export default function EditApplicationSettings({ appSettings, props }) { return ( <button className="button-red" onClick={() => props.changeState(false)} > Cancel </button> ); }

Cuando hago clic en el botón, eso debería cambiar el estado en parent , pero en su lugar, aparece un error .

 TypeError: Cannot read properties of undefined (reading 'changeState')

¿En qué me equivoqué al pasar los apoyos?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

En términos de React, props tiende a referirse a todo el objeto de propiedad:

 EditApplicationSettings(props)

Pero dado que está desestructurando las propiedades del objeto, debe hacer referencia explícitamente a la propiedad changeState :

 EditApplicationSettings({ appSettings, changeState })

y

 onClick={() => changeState(false)}
about 4 years ago · Juan Pablo Isaza Report

0

Para solucionar este error

 TypeError: Cannot read properties of undefined (reading 'changeState')

entonces esta linea

 export default function EditApplicationSettings({ appSettings, props }) {

debiera ser

 export default function EditApplicationSettings({ appSettings, ...props }) { ^^^

Puede leer más en MDN doc para la asignación de desestructuración

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!