-
Notifications
You must be signed in to change notification settings - Fork 118
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
Extract Skeleton Items to another component then reuse it? #56
Comments
hmmm, good catch |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: