Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!