Skip to content

Instantly share code, notes, and snippets.

@devethan
Last active May 7, 2021 05:48
Show Gist options
  • Save devethan/6ac865de1d58f771ed952fbc9b4f0546 to your computer and use it in GitHub Desktop.
Save devethan/6ac865de1d58f771ed952fbc9b4f0546 to your computer and use it in GitHub Desktop.
Render children components with specific gap
const renderChildrenWithGap = (): Array<
React.ReactChild | React.ReactFragment | React.ReactPortal
> | null => {
return children
? Children.toArray(children).map((child, index) => {
return (
<React.Fragment key={index}>
{index !== 0 && gap ? (
<View
style={{
[flexDirection === 'column' ||
flexDirection === 'column-reverse'
? 'height'
: 'width']:
typeof gap === 'number' ? gap : theme.space[gap],
}}
/>
) : null}
{child}
</React.Fragment>
);
})
: null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment