Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: react warning on props #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ export const styled: W.Styled = function(
defaultVariants,
}
) {
const overrideVariantProps = variants
? Object.fromEntries(Object.keys(variants).map(key => [key, undefined]))
: {};
const overrideTransientProps =
transient && variants
? Object.fromEntries(
Object.keys(variants)
.filter(key => transient.includes(key))
.map(key => [key, undefined])
)
: {};
const Component = <As extends ElementType>(
{ as: asProp, ...props }: W.StyledProps<As, any, any>,
ref: any
): ReactElement<any, any> => {
const Tag = (asProp || component) as ElementType;
const isTag = typeof component === 'string';
const _props = {...props}

// remove all variants props if the component is a tag name
if(isTag) {
if(variants) {
Object.keys(variants).forEach(key => delete _props[key])
}
} else {
if(variants && transient) {
Object.keys(variants).filter(key => transient.includes(key)).forEach(key => delete _props[key])
}
}

return (
<Tag
{...defaultProps}
{...props}
// remove all variants props if the component is a tag name
{...(isTag ? overrideVariantProps : overrideTransientProps)}
{..._props}
ref={isTag ? ref : undefined}
className={
evaluateClassName(
Expand Down