React patterns: How to create a wrapper around a native HTML element
13 November 2022 (Updated 2 August 2024)
Suppose you want to create a component that is a wrapper around an existing HTML element like the <button>
element.
For example, you might want to create a <ToolbarButton>
the component that acts exactly like a button but has specific classes applied depending on whether it’s in an active state or not.
Here’s an approach you can take (example):
A simpler example:
Tagged:
React patterns
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment