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));
}}