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

216
Visualizações
React global key handler function works but gives an error when passed a function with props

I have a function that is exported from a utils folder. The function is used for handle keyboard navigation:

export function handleKeyPress(e, callback) {
    if (e.key === "Enter") {
        console.log("test", callback);
        callback();
    }
}

It is pretty simple, you can call this function on a onKeyPress action and if the key that was pressed is the enter key than whatever callback function you provide will run. This works properly in all cases, however if the callback function I pass in uses parameters I get the following console error (despite the function still running fine):

Uncaught TypeError: callback is not a function

and

Uncaught ReferenceError: process is not defined

For testing purposes I added the console.log("test", callback) and to my surprise the console log shows test undefined. Again the function is running as expected.

Any ideas what is going on? Why is the callback being shown as undefined despite it running properly.

Also when I run a function that doesn't take any params I do not get a console error and the console log comes out as expected.

I can't be positive the params are the issue because this function isn't being called in that many places, but here is an example of a call that causes the error:


const [selectedBundle, setSelectedBundle] = useState(
     purchase?.bundle || null
);
onKeyPress={(e) => {
   handleKeyPress(e, setSelectedBundle(bundle));
}}
about 4 years ago · Juan Pablo Isaza
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