"Reorganizing React components with CSS Grid: A Step-by-Step Guide

|----------|
| Form     |
|----------|   //current layout
| Bookings |
|----------|

|----------|
| Bookings |
|----------|   //desired layout
| Form     |
|----------|

Is there a way to adjust the order of components in the <main> container so that the <Bookings /> component is displayed before the <form>?

The solution should maintain the current JSX file order of components, with this change only applying at specific breakpoints.

JSX file

<main className="Form-container">
  <form className="booking-form-business">
     <WorkingHours />
  </form>
  <ContextProvider>
     <Bookings /> //main div has a 'bookings' class
  </ContextProvider>
</main>

SCSS file

.Form-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);

    .booking-form-business {
      grid-column: 1 / -1;
    }

    .bookings { //how to display this before 'booking-form-business'
      grid-column: 1 / -1;
    }
}

Answer №1

Employ the order attribute in combination with the display: grid property

.Form-container {
    .booking-form-business {
      grid-column: 1 / -1;
      order: 2;
    }
    .bookings {
      grid-column: 1 / -1;
      order: 1;
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React - The ._id received by the Modal inside the map function is incorrect

My map is generating edit and delete buttons. The delete button requires confirmation, so I implemented a modal. When I use console.log(additive._id) on the first delete button, I get the correct ._id, but when I click the confirm button inside the modal, ...

Creating a resizable textarea component in JavaScript/React that adjusts its height dynamically but stops growing when

I am looking to create a textarea that initially displays as a single line but can expand up to 4 lines, and then start scrolling once the maximum height is reached. I have a solution in progress where it grows up to the limit, but does not shrink back dow ...

What is the best way to trigger a re-render of a child component when the state changes?

I'm currently using React and facing an issue with re-rendering a child custom input component when the prop state changes. Unfortunately, my attempts to make it work have been unsuccessful. In the example scenario, I am triggering the prop state cha ...

Error encountered with Content Security Policy while utilizing react-stripe

I am currently in the process of developing a React application that incorporates Stripe payments utilizing the @stripe/react-stripe-js (version "^1.9.0") and @stripe/stripe-js (version "^1.32.0") npm packages. While the payments are functioning correctly, ...

State in Formik Form requires a double-click to update

While utilizing Formik to create a checkout form, I encountered an issue where the data logged to my console after clicking the submit button does not reflect any changes until the second click. onSubmit={(values) => { addData(values); ...

Modify the background color of the text area to white when it is selected using CSS3

In my css code snippet, I have defined the styling for a registration form which includes various rules for different elements like input fields, labels, and text areas. .register { width: 400px; margin: 10px auto; padding: 10px; border: 1 ...

Creating a server rack visualization using HTML/CSS or a Python library

Is there a specific library or template available to assist in creating a visual representation of server racks, utilizing the placement of servers within the rack as input parameters? For example: Server Name - Start U - End U Servers1 - 15 - 17 Server2 ...

I find myself struggling to manage my javascript dependencies

Currently, I am utilizing NPM along with various angular packages. As per the tutorial on Basic Grid Part 1 at this link, I am encountering challenges. This is my file directory structure: D:/nodeStuff/uiGrid includes: node_modules uigrid.css uigrid.h ...

Tips for adjusting the border color of a MUI Select field

https://i.stack.imgur.com/rQOdg.png This MUI select box changes color from blue to black based on selection. The challenge is to customize the text and border color to white (currently set as blue). Any suggestions on how to achieve this? ...

Filling a table cell with a div that spans 100% height

I am currently working with Bootstrap and I am attempting to create three columns filled with text overlaying a rectangle. The squares within the columns should have equal height and there needs to be spacing between them. Through the use of display:table ...

Update the state when a button is clicked and send a request using Axios

Currently in my front end (using react): import '../styles/TourPage.css'; import React, { Component } from 'react'; import axios from 'axios' class TourPage extends Component { constructor(props) { super(p ...

`returning a functional component directly from a component's event listener`

Recently, I started exploring React and came across an issue with React Router integration. I have a React menu component that includes hyperlinks in a sidenav for navigation to other components. However, the standard React Routing method doesn't see ...

Is there a way to dynamically incorporate line numbers into Google Code Prettify?

Having some trouble with formatting code and inserting/removing line numbers dynamically. The line numbers appear on the first page load, but disappear after clicking run. They don't show at all on my website. I want to allow users to click a button a ...

"Learn how to add up elements in an array based on their unique IDs and generate a new array using

There is an array called data that looks like this: const data = [ {"id": "One", "number": 100}, {"id": "One", "number": 150}, {"id": "One", "number": 200}, ...

Pseudo elements disappear when utilizing Flexbox

I am looking to create two divs that each take up 100% width, but I am open to other configurations. Additionally, the active tab should have an arrow displaying below it. Despite using flex-grow in my flexbox setup, the placement of the after pseudo-elem ...

Introducing dependencies into a React hook can trigger an endless cycle of updates

I'm encountering an issue when attempting to update a state using props passed down from the parent component in React. However, I keep receiving a warning message from React advising me to include the state being updated in the dependency list. The ...

Error: Attempting to access a property named '_updatedFibers' on an undefined object is not possible due to a TypeError

I encountered the following error: Uncaught TypeError: Cannot read properties of undefined (reading '_updatedFibers') at requestUpdateLane (react-dom.development.js:25411:23) at updateContainer (react-dom.development.js:28810:14) at ReactDOMHydra ...

What are the steps for creating personalized sliders with WordPress?

Seeking guidance on how to code WP Template files to enable control from the WP dashboard for adding or removing slider images. A sample code snippet is provided below. <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indi ...

Tips for accessing specific product information based on its unique identifier in a Reactjs and Laravel Application

Looking for assistance to display selected product details utilizing React and Laravel. Once a product is selected, the ProductDetails page should show all relevant details of the chosen product. However, I am encountering issues where I only receive data ...

How can I determine if text inside a tag is visible on a webpage using JavaScript or React?

As a beginner in programming, I am looking to verify if the h3 tag containing the text "hello" is present within the document. Let's examine the following HTML: <div class= "parent_div"> <div class="child_div"> <h3>hell ...