Home > Mobile >  How to perform multiple actions when clicking on a button component?
How to perform multiple actions when clicking on a button component?

Time:08-07

I created a button in solid-js and I would like that when this button is clicked, a page is opened and the counter goes to zero. To perform these operations, I have already created two functions. I would like to ensure that when clicking this button that these two functions are called asynchronously. So I wrote the following code:

 <button
        onClick={[toggle, setNullCount]}
      >

with functions to call toggle and setNullCount. However, I realized that when I click on the button, only the first declared function is called and I don't know how to allow two functions to be called on click.

CodePudding user response:

Here is a solution

onClick={() => {toggle(); setNullCount()}}

when you want assign more than one action to trigger you must create a function which handles methods that will be performed as effect.

CodePudding user response:

You need to create a single handler function that calls both handlers:

<button
  onClick={() => {
    toggle();
    setNullCount();
  }}
>
  • Related