@uiw/react-native
Version:
UIW for React Native
31 lines • 883 B
JavaScript
import React, { Fragment } from 'react';
import { Text } from 'react-native';
export default function Div({
children,
...otherProps
}) {
if (!children) {
return null;
}
const someStr = React.Children.toArray(children).every(item => {
// eslint-disable-next-line no-mixed-operators
return typeof item === 'string' || item && item.type && item.type.displayName === 'Text';
});
if (someStr) {
return <Text {...otherProps} children={children} />;
}
return <Fragment>
{React.Children.toArray(children).map((child, idx) => {
if (typeof child === 'string') {
return <Text {...otherProps} children={child} key={idx} />;
}
if (!React.isValidElement(child)) {
return undefined;
}
return React.cloneElement(child, {
key: idx,
...otherProps
});
}).filter(Boolean)}
</Fragment>;
}