Difficulty using Container, Row, and Col components in React-Bootstrap

Currently, I am diving into the world of React and React-Bootstrap to expand my skill set.

My focus is on utilizing the React-Bootstrap grid layout effectively. However, I suspect that I might be doing something wrong in my implementation. It seems like the "Container, Col, Row" functionality is not working as expected, and I'm running out of troubleshooting ideas.

What could be causing this issue?

Details from package.json:

  "dependencies": {
    "bootstrap": "^4.3.1",
    "jquery": "^3.0.0",
    "react": "^16.8.4",
    "react-bootstrap": "^1.0.0-beta.6",
    "react-dom": "^16.8.4",
    "react-scripts": "2.1.8",
    "typescript": "^3.3.4000"

Information from the package.json in the "bootstrap" directory:

  "_from": "bootstrap@latest",
  "_id": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50323f3f24232422312010647e637e61">[email protected]</a>",

Details from the package.json in the "react-bootstrap" directory:

  "_from": "react-bootstrap@^1.0.0-beta.6",
  "_id": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1a3b4b0b2a5fcb3bebea5a2a5a3b0a191e0ffe1ffe1fcb3b4a5b0ffe7">[email protected]</a>",

I have also attempted to install and use bootstrap@3 without success:

npm install bootstrap@3 --save npm i --save bootstrap@3

Main code snippet from index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

class Module extends React.Component
{
  constructor(props)
  {
    super(props);
  }

  clickHandler = (command) =>
  {
    // ... some handler code here
  }

  render()
  {
    return (
      <Container>
        <Row>
          <Col>
            <table>
              <tr>
                <th class="r1_header"> Header 1 </th>
                <th class="r1_header"> Header 2 </th>
                <th class="r1_header"> Header 3 </th>
              </tr>
              <tr>
                <td> <button/> </td> // some more button stuff here
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td> 
                <td> <button/> </td>
              </tr>
              <tr>
                <th class="r2_header"> Header 1 </th>
                <th class="r2_header"> Header 2 </th>
                <th class="r2_header"> Header 3 </th>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
            </table>
          </Col>
          <Col>
            // another table here... should be aligned next to the
            // prev "col" horizontally but is going underneath (vertically)
          </Col>
        </Row>
      </Container>
    );
  }
}

* UPDATE *

For a Minimal, Complete, and Verifiable Example (MCVE), check out:

codesandbox

The expected output should be HelloWorld, but it is currently displayed as:

Hello
World

Answer №1

The issue has been successfully resolved. It turned out to be a mistake on my part. I overlooked an important step in the setup instructions provided on the react-bootstrap main website regarding style sheets.

In the index.html file, make sure to accurately copy and paste the path to the latest bootstrap style sheets:

<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
  integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1G"
  crossorigin="anonymous"
/>

Answer №2

To utilize Bootstrap in your React project, you must first install the necessary packages.

Use the command: npm Install react-bootstrap bootstrap

Next, make sure to import the following line in either your index.js or App.js file:

import 'bootstrap/dist/css/bootstrap.min.css';

Once imported, you can use Bootstrap components in your project like so:

 <Container>
                <Row>
                    <Col>1</Col>
                    <Col>2</Col>
                    <Col>3</Col>
                </Row>
            </Container>

Answer №3

To create a table layout, utilize the grid system by specifying the number of columns you want for the table and the number of columns for other content out of a total of 12. See the example below:

Include Grid, Row, and Col components:

import { Row, Col, Grid } from 'react-bootstrap';

<Grid>
    <Row>
        <Col md="6">
            <table>
                <tr>
                    <th class="r1_header"> Header 1 </th>
                    <th class="r1_header"> Header 2 </th>
                    <th class="r1_header"> Header 3 </th>
                </tr>
                <tr>
                    <td> <button /> </td> // some more button stuff here
                    <td> <button /> </td>
                    <td> <button /> </td>
                </tr>
                <tr>
                    <td> <button /> </td>
                    <td> <button /> </td>
                    <td> <button /> </td>
                </tr>
                <tr>
                    <td> <button /> </td>
                    <td> <button /> </td>
                    <td> <button /> </td>
                </tr>
                <tr>
                    <th class="r2_header"> Header 1 </th>
                    <th class="r2_header"> Header 2 </th>
                    <th class="r2_header"> Header 3 </th>
                </tr>
                <tr>
                    <td> <button /> </td>
                    <td> <button /> </td>
                    <td> <button /> </td>
                </tr>
                <tr>
                    <td> <button /> </td>
                    <td> <button /> </td>
                    <td> <button /> </td>
                </tr>
                <tr>
                    <td> <button /> </td>
                    <td> <button /> </td>
                    <td> <button /> </td>
                </tr>
            </table>
        </Col>
        <Col md="6">
            {"dsfdsdsf"}
        </Col>
    </Row>
</Grid>

Answer №4

For styling using Bootstrap, don't forget to include the line

import 'bootstrap/dist/css/bootstrap.min.css';
within your index.js file. And of course, run npm install bootstrap to install the necessary packages.

Answer №5

I encountered a similar issue and after conducting extensive research, I was able to resolve it.

If you have installed the react-bootstrap bootstrap library using

npm install react-bootstrap bootstrap
, the next step is to incorporate the Bootstrap file in either index.js or app.js. In my situation, I included
import 'bootstrap/dist/css/bootstrap.min.css';
in index.js.

Now, it's time to import the Component that I am utilizing. These components are being used in App.js.

import { Image ,Button  ,Row ,Col } from "react-bootstrap"; 

I am utilizing Image, Button, Row, Col.

Here is the actual code I am using:

import logo from './logo.svg';
import './App.css';
import { Image ,Button  ,Row ,Col } from "react-bootstrap";


function App() {
  let authorName ="Pankaj Kumar";


  return (
    <div className="App">
      <span className="badge bg-danger">React JS component</span> <br />
      <Image
          src="https://dummyimage.com/170x180/000/fff.png&text=TEST123"
          thumbnail
        />

      <Row className="mx-0">
        <Button as={Col} variant="primary">Button #1</Button>
        <Button as={Col} variant="secondary" className="mx-2">Button #2</Button>
        <Button as={Col} variant="success">Button #3</Button>
      </Row>

    </div>
 );
}

export default App;

Output :

https://i.sstatic.net/W1UHf.png

For more information, visit:

Answer №6

I have successfully resolved the issue. It was a mistake on my end where I overlooked a crucial part of the setup mentioned in the react-bootstrap documentation related to style sheets.

To resolve this, in index.html, simply copy and paste the path to the latest bootstrap style sheets:

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2909d9d868186809382b2c7dcc3dcc1">[email protected]</a>/dist/css/bootstrap.min.css"
  integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
  crossorigin="anonymous"
/>

`

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

Retrieve the ReadStream from Firebase Storage and provide it as input to the Openai API

I am struggling to retrieve an image from firebase storage and transmit it to an openai endpoint Here is my current code snippet: const fileStorage = await getStorageAdmin(uid, "/sample.png"); const file = fileStorage.createReadStream(); co ...

What is the reason behind jQuery's .html("abc") only providing temporary insertion?

I have come across an issue with an HTML button that triggers a function. Whenever the button is clicked, a div is inserted but it only appears for a brief moment before disappearing both visually and in the HTML tree. function openBox () { $( '#0&a ...

Creating a table with a static first column and vertical text positioned to the left of the fixed column

To create a table with the first column fixed, refer to this fiddle link: http://jsfiddle.net/Yw679/6/. You also need a vertical text to be positioned to the left of the fixed column in a way that it remains fixed like the first column. The disparities be ...

When invoking the function, the original state remains unaffected within a separate function

Whenever I click on an 'item', it should establish an initial value for me to use in a comparison within another function that involves the mousemove event. However, when the mousemove function is triggered, the initial state remains at 0. imp ...

Adding react-hook-form as an external library in webpack: A step-by-step guide

I'm currently working on a form where I'm trying to integrate react-dropzone with react-hook-form. In order to achieve this, I referred to a Github discussion found here: https://github.com/react-hook-form/react-hook-form/discussions/2146. Howeve ...

Interactive mobile navigation featuring clickable elements within dropdown menus

I recently implemented a mobile nav menu based on instructions from a YouTube tutorial that I found here. Everything was working perfectly until I encountered an issue on the 'reviews list' page. The dropdown in the mobile nav is supposed to be ...

Leveraging AngularJS to fetch data from two distinct JSON files

I am faced with the challenge of incorporating 2 JSON file examples into my project. The format of each file is different, so I am exploring the best approach using an angular controller to handle them effectively. These JSON files are not being fetched fr ...

Accessing a React application via a hyperlink within an HTML file

I'm dealing with a situation where I have an HTML file containing a list of links. While some of the links direct to other HTML files, I'm trying to have one link lead to a React application. However, I have not had success in opening the app lik ...

Uploading a large number of images to GCP Bucket results in a failure to connect to the oauth2 token

After writing a NodeJS upload function for Google Cloud bucket, I encountered an issue when trying to upload a larger dataset of over 3000 images. Initially, the uploading process seemed smooth, but then suddenly an error occurred and only some of the imag ...

What is the best approach to unit testing this React Component?

I have created a component that acts as a wrapper for another component. My question is, how should I approach unit testing for this component? Besides checking the state and method calls to ensure they update the state correctly. Other than rendering pro ...

Tables that adapt to different screen sizes, displaying perfectly on desktop but with slight variations on mobile devices

I recently experimented with a demo to enhance the performance of tables on my website in development. The demo worked flawlessly on my desktop when I resized using a responsive tester extension for Chrome: https://i.stack.imgur.com/KzFiR.jpg However, u ...

Can you explain the function of the "Normalize CSS" feature in Fiddle?

I recently came across this interesting fiddle: Demonstration of rounded corners It achieves the desired outcome, however, I noticed that it only works properly when the "Normalised CSS" checkbox is selected. When it's not checked (like in my code), ...

The NextJS routing feature displays the [slug] parameter in the URL

I am encountering an issue with my NextJS app's folder structure: - pages - docs - [slug] - index - [id] - index These pages are intended to be dynamic, displaying data dynamically on the UI. This means that users can navigate t ...

Guide to showcasing a placeholder in MUI's Select component

How can I add the placeholder "Select a brand" to this select element? I've tried different options with no luck. Here is the code snippet I am working with: <FormControl fullWidth> <InputLabel id="demo-multiple-name-label" ...

Getting a 401 error when using the Companies House API with jQuery and ajax

I attempted to retrieve JSON data from the UK Companies House API but encountered a 401 error An error occurred: the server responded with a status of 401 (Unauthorized) I implemented jQuery with the ajax() method for this task, and here is a snippet o ...

python conducting automation tests with Selenium WebDriver on a mouse

Hello, I'm having trouble with opening the Mouser website and using the search bar to send some data. Below is a sample of the code I've been working on, but I can't seem to find the correct CSS selector. Any help would be greatly appreciate ...

Troubles with CSS in MUI Component Integration

How can I successfully implement a vertical timeline using Material UI in React? I've set it up, but the CSS isn't functioning as expected. Is there an error in my implementation? List of Dependencies: "@emotion/react": "^11.11.1& ...

Disregard any labels when it comes to clickable areas for mouse events

Here is a simple example in JSFiddle where a text is displayed over an image inside a div element. Depending on where the cursor hovers, it can exhibit three different behaviors: pointing hand over the image, allowing text selection over the content of the ...

Store user input in a paragraph

I want to create a unique program that allows users to input text in a field, and when they click "Start", the text will appear in a paragraph backwards. I plan to use Html, jQuery, and CSS for this project. Can anyone provide guidance on how to achieve th ...

"Obtaining Google locations within a modal box - a step-by-step

Having trouble with my Google Places search integration in Angular 2. <input type="text" type="text" class="form-control" placeholder="Address" [ngClass]="{active:signupSubmitted && !signUpForm.controls['formatted_address'].valid}" [ ...