Open hoangvu12 opened 3 years ago
hmmm, good catch I'll try to do something to make it work
hmmm, good catch I'll try to do something to make it work
After looking at your source code, I figured out why it didn't work. So I tried this approach, take a look at it to see if it helps.
const getChildren = React.useCallback(
(element: JSX.Element | JSX.Element[]) => {
return React.Children.map(element, (child: JSX.Element, index: number) => {
// If the component neither SkeletonItem nor View.
// Then assume it is a custom component that using SkeletonPlaceholder
// just return it directly.
if (
child.type.displayName !== "SkeletonPlaceholderItem" ||
child.type.displayName !== "View"
) {
return child;
}
let style: ViewStyle;
if (child.type.displayName === "SkeletonPlaceholderItem") {
const { children, ...styles } = child.props;
style = styles;
} else {
style = child.props.style;
}
if (child.props.children) {
return (
<View key={index} style={style}>
{getChildren(child.props.children)}
</View>
);
} else {
return (
<View key={index} style={styles.childContainer}>
<View style={[style, viewStyle]} />
</View>
);
}
});
},
[viewStyle]
);
is this issue solved? im trying to make my component reusable
I have a component called
Loader.tsx
Now I create a component contains Skeleton items
Now when I try to use it in HomeScreen, I would write
Sadly this way didn't works as I expected. This should works but somehow it didn't...
Edit: After minutes of trying, I found out this way works as I expected. But the syntax looks not that good.