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

Adjust logic responsible for cloning elements #19

Open
wants to merge 2 commits 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
20 changes: 8 additions & 12 deletions src/create-restyle-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ export function createRestyleProps(
if (Styles) {
const stylesToRender = React.createElement(Styles, { key: 'rss' })

if (props.children) {
if (props.children.constructor === Array) {
props.children = props.children.concat(stylesToRender)
} else if (typeof props.children === 'string') {
props.children = [props.children, stylesToRender]
} else {
props.children = [
React.cloneElement(props.children, { key: 'rse' }),
stylesToRender,
]
}
if (Array.isArray(props.children)) {
props.children = props.children.concat(stylesToRender)
} else if (props.children && typeof props.children === 'object' && 'type' in props.children) {
props.children = [
React.cloneElement(props.children, { key: 'rse' }),
stylesToRender,
]
} else {
props.children = stylesToRender
props.children = [props.children, stylesToRender]
}
}

Expand Down