Components / Layout

Spacer

Spacer eats the leftover main-axis space inside a flex container. It does nothing else. Reach for it when you need to push siblings to opposite edges of a row or column.

Loading playground…
Updated 3 days agoEdit on GitHubWeb & native

What it is

A <Box flex={1}>. Spacer accepts every Box prop, so you can override flex if you ever need a spacer with a fractional weight. The named primitive exists because <Spacer /> at the call site reads more clearly than <Box flex={1} />.

Install

Spacer is exported from usemotif. No separate install.

example.tsx
import { Spacer } from 'usemotif';

API

Spacer

stable
function Spacer(props: SpacerProps): JSX.Element
…BoxPropsBoxProps

Every prop Box accepts. `flex` defaults to `1` and can be overridden.

Examples

Toolbar with actions pushed to the right:

example.tsx
<HStack alignItems="center">
<Logo />
<Spacer />
<Button>Sign in</Button>
</HStack>

Equal-width slots — give each Spacer the same flex weight:

example.tsx
<HStack>
<Spacer />
<Button>One</Button>
<Spacer />
<Button>Two</Button>
<Spacer />
</HStack>