DEV Community

Cover image for React, Vue and Svelte: Comparing Click Event
Clément Creusat
Clément Creusat

Posted on

React, Vue and Svelte: Comparing Click Event

Click Event in...

The use of the click directive is quite similar in these 3 frameworks.

Check it out 🚀

React

Link

const handleClick = () => {
  alert('I was clicked!')
}

<button
  onClick={handleClick}
  className="button">Click me!</button>
Enter fullscreen mode Exit fullscreen mode

Vue

Link

const handleClick = () => {
  alert('I was clicked!')
}

<button
  @click="handleClick"
  class="button">Click me!</button>
Enter fullscreen mode Exit fullscreen mode

Svelte

Link

const handleClick = () => {
  alert('I was clicked!')
}

<button
  on:click={handleClick}
  class="button">Click me!</button>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)