Using Bootstrap SCSS in ReactJS without applying Bootstrap CSS classes

After successfully installing bootstrap using the following command:

npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9bbb6b6adaaadabb8a999edf7e9f7e9f4b8b5a9b1b8f7ef">[email protected]</a> --save

my dependency list now includes:

 "dependencies": {
    "bootstrap": "^4.0.0-alpha.6",
    "react": "^15.6.1",
    "react-dom": "^15.6.1"
  }

In my styles.scss file, I imported Bootstrap like this:

@import '~bootstrap/scss/bootstrap';

Furthermore, here is a snippet from my webpack configuration:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
    template: './src/index.html',
    filename: 'index.html',
    inject: 'body'
})

module.exports = {
    entry: './src/index.js',
    output: {
        path: __dirname + '/dist',
        filename: 'build.js'
    },
    devServer: {
        historyApiFallback: true
    },
    module: {
        loaders: [
            { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
            { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
            {
                test: /\.scss$/,
                use: [
                    'style-loader',
                    'css-loader?importLoaders=1&modules&localIdentName=[name]_[local]_[hash:base64:5]',
                    'sass-loader',
                ],
            }
        ]
    },
    plugins: [HtmlWebpackPluginConfig]
}

However, when I apply the container class in my header component:

import React from 'react';

export class Header extends React.Component {
    render() {
        return(
          <header className="container">header here</header>
        );
    }
}

export default Header;

The display outcome is not as expected:

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

Moreover, upon inspection of build.js, I'm unable to locate the .container class, as well as .row, and others.

Examining the contents of bootstrap.scss, the container style appears as follows:

@if $enable-grid-classes {
  .container {
    @include make-container();
    @include make-container-max-widths();
  }
}

Additionally, within the _variables.scss file of Bootstrap, the variable is defined as:

$enable-grid-classes:       true !default;

So, what could be causing this issue?

Answer №1

To include your .scss file in your component and use it in your HTML, follow these steps:

import React from 'react';
import styles from './styles.scss'; // import your .scss file

export class Header extends React.Component {
    render() {
        return(
          <header className={styles.container}>header here</header>
        );
    }
}

export default Header;

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

Eliminating the excess space at the beginning of dialogues

I'm struggling with removing the unwanted whitespace above the title in my Material UI dialog popup. Even after applying a background color to the title and content area, I still have a white margin at the top that I can't seem to eliminate. Doe ...

The comparison of display and if else in ReactJS form control

Currently, I am tackling a large form with multiple branches. My main point of interest is whether there exists any noticeable difference in performance when utilizing the following code: <Box display={type == type.RatioBased ? "none" : " ...

Content displayed in the center of a modal

Struggling to center the captcha when clicking the submit button. Check out the provided jsfiddle for more details. https://jsfiddle.net/rzant4kb/ <script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-protection" class=" ...

CSS - borders are overlapping with one another

Encountering an issue where the bottom border is overlapping the right border on the same element. Here's a visual representation of the problem: The green right border's bottom is appearing distorted due to the presence of the gray border at t ...

Best practices for safely handling dynamic keys in Typescript

I am searching for a secure method to create keyed objects in this manner: interface Types { RED: 'RED'; BLUE: 'BLUE'; GREEN: 'GREEN'; } type TypeKeys = keyof Types; const COLORS: Types = { RED: 'RED', B ...

Using ReactJS to capture keydown events from an iframe

I am trying to implement keydown event handling for an iframe within a ReactJS component. The iframe contains an embedded video, and I want to be able to capture keyboard events while the video is playing. Can someone please assist me with how to achieve ...

What is the most effective way to create a live preview using AngularJS and CSS?

Is there a way to dynamically change the background color of the body based on the hexadecimal value entered in a textfield, without using jQuery? I want the change to happen live as the user types. The current code works but it doesn't feel right. I ...

The screen reader seems to be malfunctioning as soon as I include this particular code

//Finding the height of the header let headerHeight = document.querySelector('header'); let height = headerHeight.offsetHeight; //Adjusting the #navbarNav's top margin to accommodate the header let nn = docu ...

Transform a list element into three separate rows using Bootstrap

I need assistance wrapping a list of elements into 3 columns using a single <ul> Here is a visual representation of what I am aiming for: https://i.sstatic.net/dptO2.png <ul class="list-group list-group-flush row-cols-3"> <li ...

Create a select field that dynamically displays other select fields based on the id of the selected option

I am currently working on a project using material-ui and React. I have a component with a SelectField that is nested within another component, making it the grandchild of the parent component. My goal is to retrieve the selected value from this first Sele ...

Encountering problems with the 'Link' component in React Router DOM v6 while using React Testing Library

In my project, I have a special component that includes a Link element from the react router dom v6. This component is called MyComponent.jsx. ... <Link to='/path'> Some Text </Link> ... However, when I attempt to display this ...

React Native Debugger Issue - Unable to Access /debugger-ui/

Every time I try to load React Native Debugger, it automatically directs me to http://localhost:8081/debugger-ui/. Unfortunately, I am encountering the following error message - Cannot GET /debugger-ui/ ...

Is there a way to ensure certain items are displayed on different lines?

Currently, I am working on styling an HTML list with the following properties: font-weight: bold; padding: 0px; margin: 0px; list-style-type: none; display: block; width:700px; font-size: 14px; white-space: pre-wrap; The individual cells within this list ...

How to create an onClick event handler in ReactJS and pass 'this' parameter

Here is the code for my component: import React, {PropTypes} from 'react'; export default class Viewdesc extends React.Component { render() { return ( <div className="col-md-12 slide-row"> <div className="col-md-12 overview- ...

Ways to identify when the last item in a list has been reached during scrolling

Is there a way to determine when you've reached the end of a list element during a scroll event? For example, if I have an array like [1,2,3,4,5,6,7,8,9,10], how can I detect when the scroll has reached the end of the list and return the value at that ...

Adjust the dimensions of the embedded Google document

Currently, I am in the process of developing a website for my initial client and I'm encountering some difficulty in adjusting the size and background color of an embedded google doc. If anyone could provide assistance, it would be greatly appreciated ...

Collecting data with Selenium as elements load [Python]

Is there a way to scrape only the newly generated items in sequence? I have a dynamic list that loads with scrolling. There are two methods I can use to scrape all generated divs: Scroll to the bottom of the list and then scrape all generated divs. Scroll ...

The child component fails to inherit the data types provided by the parent component

I am currently working on setting up a dynamic table that will receive updates from the backend based on actions taken, which is why I need to pass the endpoint and response model. When I try to nest and pass the response type, it seems to get lost in the ...

Unable to navigate between tabs in Bootstrap 5 navigation tabs

I am currently working on developing a login page that includes two tabs - one for logging in and another for registering. The login tab displays fields for username and password, while the register tab includes fields for name, last name, and email. I h ...

What steps can be taken to resolve the error message "Warning: useLayoutEffect does not have any effect on the server"?

Here is the error message I keep encountering: Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and ...