Skip to content

Instantly share code, notes, and snippets.

@its-monotype
Created December 11, 2022 17:43
Show Gist options
  • Save its-monotype/c99fde332d5433895e536d1fb2dd5d04 to your computer and use it in GitHub Desktop.
Save its-monotype/c99fde332d5433895e536d1fb2dd5d04 to your computer and use it in GitHub Desktop.
withClassName (no forwardRef)
export function withClassName<Props extends object>(
WrappedComponent:
| React.ComponentType<Props>
| React.ForwardRefExoticComponent<Props>,
classes?: string,
) {
const WithClassName = (props: Props & { className?: string }) =>
React.createElement(WrappedComponent, {
...props,
className: clsx(props.className, classes),
});
if (__DEV__) {
WithClassName.displayName = `WithClassName(${getDisplayName(
WrappedComponent,
)})`;
}
return WithClassName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment