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

142
Vistas
How to pass value from child component(function based component )to parent component(class based component)

I need to pass the value from the child component to the parent component The child component is function based component and parent component is class based

child component

export const Checkbox = (props) =>{
const [checked,setChecked] = useState(false);
return (
        <Checkbox
            label={"XYZ"}
            value={checked}
            onChange={() => setChecked((checked) =>!checked)}
            />
);
}

Parent Component(classbased component)

render(){
  return(
   <Checkbox checked={this.props.value}>//not sure if i can get value like this
)
}

I want to get the boolean value of the check box if it is checked or unchecked

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Handle your state and function in the parent component and pass the function as a prop to child component and try to invoke the function call within child component on onChange to lift your state up to parent.

I am in hurry and just adding an idea how can you achieve this in code.

const Parent = () => {

const [checked,setChecked] = useState(false);

    const changeYourState = (newState) => {
       // change your state here
    }

    return (
        <Child
            value={checked}
            initialState={checked}
            stateHandler={changeYourState}
            />
);
}

const Child = ({ stateHandler, initialState}) => {
   //you can manipulate your initial state based on your use case 

    return (
        <div >
            onChange={() => stateHandler(initialState)}
        </div>
    )
);
}
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