Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda