Skip to main content
100%

Basic example of a Button component in ReactJs.

✓ Published0🌍 Public
Aabonello
Last edited Jul 19, 2021
Created on Dec 30, 2021

This example demonstrates a reusable Button component built with React’s `forwardRef` API and TypeScript interfaces. It shows how the component accepts standard `ButtonHTMLAttributes` while adding a custom `primary` boolean prop to conditionally apply a `btn-primary` CSS class. The implementation spreads the remaining props onto the underlying HTML `<button>` element and forwards the `ref` for imperative access. The code highlights a pattern for extending native HTML elements with additional styling logic, using the `React.ButtonHTMLAttributes` type and `forwardRef` for proper ref handling in React components.

AI-generated description

Similar vizzes