Skip to content

Instantly share code, notes, and snippets.

@codemile
Created July 19, 2021 12:20
Show Gist options
  • Save codemile/e952c58dd24c8a9a8f0e3f8b1f47399e to your computer and use it in GitHub Desktop.
Save codemile/e952c58dd24c8a9a8f0e3f8b1f47399e to your computer and use it in GitHub Desktop.
Basic example of a Button component in ReactJs.
import {ButtonHTMLAttributes, forwardRef} from 'react';
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
primary?: boolean;
}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({className, primary, children, ...props}, ref) => {
return (
<button
className={`btn ${primary ? 'btn-primary' : ''} ${className}`}
{...props}
ref={ref}
>
{children}
</button>
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment