gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
Write React component for a reusable button with callback with Tailwind styling
- User
Write React component for a reusable button with callback with Tailwind styling
- Assistant
Here is an example of a React component that implements a reusable button with callback and Tailwind styling:
import React from "react"; import PropTypes from "prop-types"; const Button = ({ onClick, children, className }) => ( <button className={`bg-blue-500 text-white font-bold py-2 px-4 rounded ${className}`} onClick={onClick} > {children} </button> ); Button.propTypes = { onClick: PropTypes.func.isRequired, children: PropTypes.node.isRequired, className: PropTypes.string, }; Button.defaultProps = { className: "", }; export default Button;The
Buttoncomponent takes three props:onClick: a function to be called when the button is clickedchildren: the content of the buttonclassName: an optional extra class name for further styling customization