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

281
Views
React js, pase una función con parámetros como accesorios sin usar esta palabra clave

Tengo un componente secundario que tiene un botón Guardar. Sin embargo, solo puedo definir la función de guardar dentro del componente principal. Necesito pasar la función como accesorio al componente secundario junto con sus parámetros. Todos los métodos que encontré usan .this, renders y constructores. Necesito una forma de usar las funciones de reacción modernas.

 export function childComponent (props) { let { handleSave, item, list } = props; return ( //Saves item in list <button className="palletSaveButton" onClick={handleSave(item, list)}> Save </button> ) } const ParentComponent = () => { let list = [{...}]; let item = {...}; function handleSaveClick(item, list) { list.push(item) } return ( <childComponent handleSave={() => handleSaveClick(item, list)} /> ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La dificultad es entender si desea que la list y el item sean SIEMPRE del Padre como fuente de verdad, o si está tratando de pasar esas variables DEL hijo AL padre.

 export function childComponent ({handleSave}) { return ( //Saves item in list <button className="palletSaveButton" onClick={handleSave}> Save </button> ) } const ParentComponent = () => { let list = [{...}] let item = {...} function handleSaveClick() { list.push(item) } return ( <childComponent handleSave={handleSaveClick} /> ); }

Si simplemente está buscando hacer clic en un botón en el elemento secundario, y la lógica/los valores se almacenan en el elemento principal, esto debería resolver su problema. Pero tengo la sensación de que está tratando de manipular las variables del niño y enviarlas al padre.

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!