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

113
Visualizações
Pass data via on click from child component to parent component react

I am new to React and trying to pass data (director, nonDirector) from my child functional component to a parent class component.

My code is below, what do I need to do to make it work?

Class parent component

export default class ProfileEditor extends React.Component<IProfileEditorProps, IProfileEditorState> {
    
      constructor(props: IProfileEditorProps) {
        super(props);
        this.state = {
          data: null,
        }
         this.updateProfile = this.updateProfile.bind(this);
      }

    public updateProfile(director, nonDirector) {

        console.log('hello', director, nonDirector);

     }

      <MultiSelect
        options={ profile?.Declarations.length == 0 ? countries : this.combineProfileAndCountrys() }   
        updateProfile={updateProfile()}
      />

Child functional component

export const MultiSelect = ({ options, updateProfile }) => { 

const [nonDirector, setNonDirector] = React.useState();
const [director, setDirector] = React.useState();

<PrimaryButton text='Save' onClick={ updateProfile(nonDirector, director) } />
    </Fragment>
);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your parent component you shouldn't be calling the function in the onClick handler. You want to pass the reference to the function to it instead.

updateProfile={updateProfile}

A similar issue is occurring in your child component. You don't want to call the function and have the results of it returned to the handler, you want to assign a function to the handler that can then call the updateProfile function when its triggered.

onClick={() => updateProfile(nonDirector, director)}
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