Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

278
Vistas
React js, pass a function with parameters as props without using this keyword

I have a child component that has a save button. However, I can only define the saving function inside the Parent component. I need to pass the function as a props to the child component along with its parameters. All the methods I found uses .this, renders and constructors. I need a way using the modern react functions.

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 Respuestas
Responde la pregunta

0

The difficulty is understanding if you want the list and item to ALWAYS be from the Parent as the source of truth, or if you are trying to pass those variables FROM the child TO the parent.

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} />
    );
}

If you simply are looking to click a button on the child, and the logic/values are store in the parent, this should solve your problem. But there's a feeling I'm getting that you are trying to manipulate the variables from the child and send those to the parent.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda