Skip to content

Commit 24f4a9d

Browse files
committed
Fix #6
1 parent ac5030e commit 24f4a9d

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/Columns/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const Columns = (props: Props) => {
3636
...rest
3737
} = props
3838
const { resolveResponsiveProp, currentBreakpoint } = useBreakpoint()
39-
const isLast = lastFactory(children)
39+
const elements = Children.toArray(children)
40+
const isLast = lastFactory(elements)
4041
const debugStyle = useDebugStyle()
4142

4243
const alignX = resolveResponsiveProp(responsiveAlignX)
@@ -67,7 +68,7 @@ export const Columns = (props: Props) => {
6768
]}
6869
{...rest}
6970
>
70-
{Children.map(children, (child, index) => {
71+
{elements.map((child, index) => {
7172
const marginStyle = isLast(index) ? noLastMargin : spacing
7273

7374
return isValidElement(child)

src/Inline/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const Inline = (props: Props) => {
2222
const margin = useSpacing(resolveResponsiveProp(space))
2323
const align = resolveResponsiveProp(responsiveAlign)
2424
const debugStyle = useDebugStyle()
25+
const elements = Children.toArray(children)
2526

2627
return (
2728
<View style={style} {...rest}>
@@ -33,7 +34,7 @@ export const Inline = (props: Props) => {
3334
{ marginTop: -margin, marginRight: -margin },
3435
]}
3536
>
36-
{Children.map(children, child => {
37+
{elements.map(child => {
3738
return isValidElement(child)
3839
? cloneElement(child, {
3940
...child.props,

src/Stack/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ export const Stack = (props: Props) => {
2323

2424
const margin = useSpacing(resolveResponsiveProp(space))
2525
const align = resolveResponsiveProp(responsiveAlign)
26-
const isLast = lastFactory(children)
26+
const elements = Children.toArray(children)
27+
const isLast = lastFactory(elements)
2728

2829
return (
2930
<View
3031
style={[style, styles.fullWidth, resolveDirection('column'), resolveAlign(align)]}
3132
{...rest}
3233
>
33-
{Children.map(children, (child, index) => {
34+
{elements.map((child, index) => {
3435
return isValidElement(child)
3536
? cloneElement(child, {
3637
...child.props,

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const normalizeResponsiveProp = <T>(value: ResponsiveProp<T>): Readonly<[T, T, T
9595
export const randomColor = () =>
9696
`rgba(${[randomByte(), randomByte(), randomByte(), 0.2].join(',')})`
9797

98-
export const lastFactory = (elements: React.ReactNode) => (index: number) =>
98+
export const lastFactory = (elements: ReturnType<typeof Children.toArray>) => (index: number) =>
9999
index === Children.count(elements) - 1
100100

101101
export const splitEvery = <T>(n: number, list: T[]) => {

0 commit comments

Comments
 (0)