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

178
Visualizações
What type is passed to functions from `onClick`?

I have some javascript that looks like this:

const menu = (
        <Menu onClick={handleMenuClick}>
            {menuItems.map((item) => (
                <Menu.Item key={item.key} icon={item.icon} style={styles.item}>
                    <span style={{ marginLeft: "5px" }}>{item.value}</span>
                </Menu.Item>
            ))}
        </Menu>
    )

With the key piece being the handleMenuClick

That function is defined as:

    const handleMenuClick = (event) => {
        console.log(event.key)
        console.log(typeof (event.key))
    }

However, I'm not sure what type the event is, and how it's getting the key value?

Additionally, when I try this in typescript, it looks like its a Synthetic event. However, I try to access the key value with e.target.value and I keep getting errors.

So I'm not sure what I'm not understanding

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When you have a TS function that takes a callback, and you want to define the callback elsewhere but aren't sure of the right typing to use, first write the function inline with the callback, and use an IDE that can tell you the types of variables. Then look at the type of the variable:

enter image description here

Then copy that type when defining a standalone callback that you can pass in.

This works not only for onClick in React, but for any situation where you're dealing with a callback you don't know the proper type for.

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