Last active
May 7, 2021 05:48
-
-
Save devethan/6ac865de1d58f771ed952fbc9b4f0546 to your computer and use it in GitHub Desktop.
Render children components with specific gap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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