Now, create a file for the button component:
// src/components/Button.jsx
import React from 'react';
import PropTypes from 'prop-types';
import './Button.css';
const Button = ({ label, onClick, primary }) => {
const mode = primary ? 'btn--primary' : 'btn--secondary';
return (
<button className={`btn ${mode}`} onClick={onClick}>
{label}
</button>
);
};
Button.propTypes = {
label: PropTypes.string.isRequired,
onClick: PropTypes.func,
primary: PropTypes.bool,
};
Button.defaultProps = {
onClick: undefined,
primary: false,
};
export default Button;