Skip to content

HStack

HStack arranges child components horizontally in a row, providing flexible spacing, alignment, and wrapping options. It’s perfect for creating navigation bars, button groups, and inline content layouts.

import { HStack } from 'rnc-theme';
<HStack spacing="md">
<Button title="First" />
<Button title="Second" />
<Button title="Third" />
</HStack>
PropTypeDefaultDescription
spacingkeyof Theme['spacing']0Gap between child components
wrapbooleanfalseAllow items to wrap to next line

HStack inherits all BaseLayoutProps for consistent styling and behavior.

PropTypeDefaultDescription
alignViewStyle['alignItems']'center'Cross-axis alignment (vertical)
justifyViewStyle['justifyContent']'flex-start'Main-axis alignment (horizontal)
PropTypeDefaultDescription
childrenReact.ReactNode-Child components to render
styleStyleProp<ViewStyle>-Additional style properties
paddingkeyof Theme['spacing']-Padding around content
marginkeyof Theme['spacing']-Margin around component
backgroundColorViewStyle['backgroundColor']-Background color
borderRadiuskeyof Theme['components']['borderRadius']-Border radius value
flexnumber-Flex grow/shrink value
widthDimensionValue-Component width
heightDimensionValue-Component height
themedbooleanfalseEnable theme styles
alignViewStyle['alignItems']-Cross-axis alignment
justifyViewStyle['justifyContent']-Main-axis alignment
<HStack
justify="space-between"
align="center"
padding="md"
backgroundColor="#fff"
style={{ borderBottomWidth: 1, borderBottomColor: '#e0e0e0' }}
>
<HStack spacing="sm" align="center">
<IconButton icon="menu" />
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>App Name</Text>
</HStack>
<HStack spacing="sm">
<IconButton icon="search" />
<IconButton icon="notifications" />
<Avatar size={32} />
</HStack>
</HStack>
<HStack spacing="md" padding="lg">
<Button
title="Cancel"
variant="outline"
flex={1}
/>
<Button
title="Save"
variant="primary"
flex={1}
/>
</HStack>
<HStack
spacing="xs"
wrap={true}
padding="md"
style={{ maxWidth: 300 }}
>
{categories.map(category => (
<Box
key={category.id}
padding="xs"
borderRadius="sm"
backgroundColor="#f0f0f0"
>
<Text style={{ fontSize: 12 }}>{category.name}</Text>
</Box>
))}
</HStack>
<HStack spacing="md" align="center" padding="md">
<Text style={{ width: 100 }}>Email:</Text>
<TextInput
placeholder="Enter your email"
flex={1}
style={{
borderWidth: 1,
borderColor: '#ccc',
padding: 8,
borderRadius: 4
}}
/>
<Button title="Verify" />
</HStack>
<HStack align="center" spacing="md" style={{ height: 60 }}>
<Text>Small</Text>
<Text style={{ fontSize: 24 }}>Large</Text>
<Text>Small</Text>
</HStack>
<HStack justify="space-between" padding="md">
<Text>Left</Text>
<Text>Center</Text>
<Text>Right</Text>
</HStack>
<HStack
wrap={true}
spacing="md"
padding="md"
>
{items.map((item, index) => (
<Box
key={index}
style={{
minWidth: 120,
flexBasis: '30%' // Responsive width
}}
padding="sm"
backgroundColor="#f5f5f5"
borderRadius="md"
>
<Text>{item.title}</Text>
</Box>
))}
</HStack>
const isTablet = useIsTablet();
<HStack
spacing={isTablet ? "lg" : "md"}
wrap={!isTablet}
justify={isTablet ? "space-between" : "flex-start"}
>
<Card flex={isTablet ? 1 : undefined}>Content 1</Card>
<Card flex={isTablet ? 1 : undefined}>Content 2</Card>
</HStack>

Spacing Guidelines

  • Use consistent spacing values from your theme
  • Prefer spacing prop over manual margins between children
  • Consider wrap={true} for dynamic content that might overflow

Alignment Tips

  • Use align="center" for mixed-height content (default behavior)
  • Use justify="space-between" for navigation-style layouts
  • Combine with flex props for responsive behavior

Common Pitfalls

  • Don’t nest HStack inside HStack unnecessarily - use spacing instead
  • Remember that wrap={true} might break your intended layout on small screens
  • Avoid setting explicit heights unless necessary for alignment