logo

Button Component with Click Event

A button component in React that handles click events.

7 Stars

Code

import React from 'react';

const Button = () => {
  const handleClick = () => {
    alert('Button clicked!');
  };

  return (
    <button onClick={handleClick} className="bg-green-500 text-white py-2 px-4 rounded">
      Click Me
    </button>
  );
};

export default Button;

Explanation

This code defines a button component that handles click events. When the button is clicked, an alert is displayed with the message 'Button clicked!'. The button is also styled using Tailwind CSS classes.