You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue when using React.cloneElement in two separate components that wrap an SVG icon. When both components use cloneElement, the styles from the first wrapper are lost in the second wrapper.
Steps to Reproduce:
IconResizer applies width, height, and flexShrink styles.
IconColorizer applies color: #FFC700.
When both are used together, only the styles from IconResizer remain, and the color is not applied.
The svg element should have both height: 16px, width: 16px, flexShrink: 0 and color: #FFC700 applied.
Actual Behavior:
The height and width from IconResizer are applied correctly.
The color from IconColorizer is missing.
Environment:
React version: 18.3.1
Browser: chrome
Possible Cause:
It seems that the second cloneElement is not properly merging the styles from the first cloneElement. This behavior is unexpected, as cloneElement is supposed to preserve existing props while overriding the specified ones.
Additional Notes:
If I manually spread the styles when creating the first cloneElement, the issue persists.
Using a single cloneElement works fine, but nesting them causes the first one's styles to be lost.
Would appreciate insights on whether this is expected behavior or a bug. Thanks!
The text was updated successfully, but these errors were encountered:
Not a react dev, but Google sent me here for a similar issue.
Took me a while to figure out, but React passes in the merged style to your component as its style prop. IconColorizer needs to use the merged style prop that React is giving it, not try to look for already-merged props on the child:
Description:
I encountered an issue when using
React.cloneElement
in two separate components that wrap an SVG icon. When both components usecloneElement
, the styles from the first wrapper are lost in the second wrapper.Steps to Reproduce:
width
,height
, andflexShrink
styles.color: #FFC700
.IconResizer
remain, and the color is not applied.Code Example:
Expected Behavior:
The
svg
element should have bothheight: 16px, width: 16px, flexShrink: 0
andcolor: #FFC700
applied.Actual Behavior:
height
andwidth
fromIconResizer
are applied correctly.color
fromIconColorizer
is missing.Environment:
18.3.1
chrome
Possible Cause:
It seems that the second
cloneElement
is not properly merging the styles from the firstcloneElement
. This behavior is unexpected, ascloneElement
is supposed to preserve existing props while overriding the specified ones.Additional Notes:
cloneElement
, the issue persists.cloneElement
works fine, but nesting them causes the first one's styles to be lost.Would appreciate insights on whether this is expected behavior or a bug. Thanks!
The text was updated successfully, but these errors were encountered: