Box

If you're looking for a flexible component to help with low-level layout needs, the Box component might be just what you need. With its customizable styles and props, it can be used to create a wide range of UI elements, from simple containers to complex layout structures.
Installation
API Reference
This is an illustration of Box component.
<Box bg="$primary500" p="$5">
<Text color="$text0">This is the Box</Text>
</Box>

Installation

Run the following command:

npx gluestack-ui add box

API Reference

To use this component in your project, include the following import statement in your file.
import { Box } from "@/components/ui/box"
export default () => <Box />

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Box

It inherits all the properties of React Native's View component.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Box with ref

A Box component with a ref property enables the direct reference and manipulation of the underlying DOM element, offering greater control and flexibility in modifying the box's appearance and behavior within a user interface.
function App() {
const myRef = useRef({})
useEffect(() => {
const styleObj = {
borderWidth: 2,
borderRadius: 4,
borderColor: "#1A91FF",
}
if (myRef.current && myRef.current.setNativeProps) {
myRef.current.setNativeProps({
style: styleObj,
})
}
}, [myRef])
return <Box h={100} w={100} bg="$primary100" ref={myRef} />
}
Edit this page on GitHub