Reputation: 347
I'm new to styled-components and I was wondering what is different styled(component) and styled(tagname) in performance issues of react.
const StyledP = styled('p')``
export const StyledComponent = props => (
<StyledP>{props.name}</StyledP>
)
const FunctionalComponent = props => (
<p className={props.className}>{props.name}</p>
)
export const StyledComponent = styled(FunctionalComponent)`
`
I looked at the this comment
and found out if I using styled(component)
.
but I don't know in performance issues of react.
can someone please explain?
Upvotes: 1
Views: 166
Reputation: 5402
Its the same API with a few additional checks in case the target is a component. Extracted from the styled
constructor source code :
const isTargetStyledComp = isStyledComponent(target);
// fold the underlying StyledComponent attrs up (implicit extend)
const finalAttrs =
// $FlowFixMe
isTargetStyledComp && target.attrs
? Array.prototype.concat(target.attrs, attrs).filter(Boolean)
: attrs;
// fold the underlying StyledComponent rules up (implicit extend)
const componentStyle = new ComponentStyle(
isTargetStyledComp ? target.componentStyle.rules.concat(rules) : rules,
finalAttrs,
styledComponentId
);
// $FlowFixMe
WrappedStyledComponent.foldedComponentIds = isTargetStyledComp
? // $FlowFixMe
Array.prototype.concat(target.foldedComponentIds, target.styledComponentId)
: EMPTY_ARRAY;
WrappedStyledComponent.target = isTargetStyledComp ? target.target : target;
To summarize:
styled(Component)
extensions.Upvotes: 1