Open In App
Related Articles

React Rebass Flexbox Wrap Component

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

React Rebass is a front-end framework that was designed keeping react in mind. In this article, we will know how to use Button Component in React rebass. Flexbox Wrap is an important component that is required in each development. So to create a Flexbox Wrap component we can import the Rebass Flexbox Wrap component.

Flexbox Wrap component is used to make a wrap using Flex Component.

Syntax:

<Flex flexWrap='wrap'>
<Box>
  <Text>Text</Text>
</Box>
<Box>
  <Text>Text</Text>
</Box>
</Flex>

Creating React Application And Installing Module:

Step 1: Create a React application using the following command.

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command.

cd foldername

Step 3: Install React Rebass in your given directory.

npm i rebass

Project Structure: It will look like the following.

Project Structure

Example: This is the basic example that shows how to use the Flexbox Wrap component.

App.js

import React from "react";
import { Flex } from "rebass";
import { Text } from "rebass";
import { Box } from "rebass";
  
const gfg = () => {
    return (
        <div id='gfg'>
            <h2>GeeksforGeeks</h2>
            <h4>React Rebass Flexbox Wrap Component</h4>
            <Flex flexWrap='wrap' mx={-2} >
                <Box width={1 / 2} px={2} py={2}>
                    <Text p={2} color='white' bg='red'>
                        1/2
                    </Text>
                </Box>
                <Box width={1 / 2} px={2} py={2}>
                    <Text p={2} color='white' bg='green'>
                        1/2
                    </Text>
                </Box>
                <Box width={1 / 3} px={2} py={2}>
                    <Text p={2} color='white' bg='black'>
                        1/3
                    </Text>
                </Box>
                <Box width={1 / 3} px={2} py={2}>
                    <Text p={2} color='white' bg='grey'>
                        1/3
                    </Text>
                </Box>
                <Box width={1 / 3} px={2} py={2}>
                    <Text p={2} color='white' bg='yellow'>
                        1/3
                    </Text>
                </Box>
                <Box width={1 / 4} px={2} py={2}>
                    <Text p={2} color='white' bg='purple'>
                        1/4
                    </Text>
                </Box>
                <Box width={1 / 4} px={2} py={2}>
                    <Text p={2} color='white' bg='gold'>
                        1/4
                    </Text>
                </Box>
                <Box width={1 / 4} px={2} py={2}>
                    <Text p={2} color='white' bg='silver'>
                        1/4
                    </Text>
                </Box>
                <Box width={1 / 4} px={2} py={2}>
                    <Text p={2} color='white' bg='blue'>
                        1/4
                    </Text>
                </Box>
            </Flex>
        </div>
    );
};
  
export default gfg;

                    

Step to Run Application: Run the application from the root directory of the project, using the following command.

npm start

Output:

Rebass Flexbox Wrap Component

Reference: https://rebassjs.org/recipes/flexbox-wrap



Last Updated : 10 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads