Skip to content

Commit

Permalink
Merge pull request #535 from jpudysz/fix/display-name-copy
Browse files Browse the repository at this point in the history
fix: copy displayName and name manually
  • Loading branch information
jpudysz authored Jan 29, 2025
2 parents fc0923a + d904221 commit 79baf09
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources:
}

export const copyComponentProperties = (Component: any, UnistylesComponent: any) => {
Object.entries(Object.getOwnPropertyDescriptors(Component)).forEach(([key, propertyDescriptor]) => {
Object.entries(Component).forEach(([key, value]) => {
// Filter out the keys we don't want to copy
if (['$$typeof', 'render'].includes(key)) {
return
}

// @ts-expect-error Copy extra component properties - example: Image.getSize, Image.displayName
UnistylesComponent[key] = propertyDescriptor.value ?? propertyDescriptor.get()
UnistylesComponent[key] = value
})

// Those are not enumerable, so we need to copy them manually
UnistylesComponent.displayName = Component.displayName
UnistylesComponent.name = Component.name

return UnistylesComponent
}

0 comments on commit 79baf09

Please sign in to comment.