Search code examples
typescriptqwik

How to set a function as the onInput$ property of an input in Qwik


I'm trying to pass a function to the onInput$ property of an input element in Qwik but it does not work.

My code is the following:

function onInput(ev: Event) {
  //Do something
}

<input onInput$={handleInput} />

And i'm getting the following error:

Internal server error: Code(25): Invalid JSXNode type. It must be either a function or a string.

Solution

  • You need to create your function using $(), like this:

    const onInput = $((ev: Event) => {
      //Do something
    });
    

    You will also have to import the $() function:

    import { $ } from "@builder.io/qwik";