Created
December 11, 2022 17:43
-
-
Save its-monotype/c99fde332d5433895e536d1fb2dd5d04 to your computer and use it in GitHub Desktop.
withClassName (no forwardRef)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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