ReactJS not responding to Bootstrap toggler button

My Bootstrap toggler button is not working in ReactJS. I did not include the jQuery scripts because I imported Bootstrap at the top. The button should only appear and function on small devices.

import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';

const Navbar = () => {

    return (
<div>
            <nav className="navbar navbar-expand-sm navbar-light bg-light">
                <div className="container">
                    <a className="home-style navbar-brand" href="/">PORTFOLIO</a>
                    <button className="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbarNav"
                        aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                        <span className="navbar-toggler-icon"></span>
                    </button>

                    <div className="collapse navbar-collapse " id="navbarNav">
                        <ul className="navbar-nav ml-auto">
                            <a className="btn-style nav-item nav-link" href="/">HOME <span className="sr-only">(current)</span></a>
                            <li >
                                <a className="btn-style nav-item nav-link" href="/about">MY STORY</a>
                            </li>
                            <li >
                                <a className="btn-style nav-item nav-link" href="/work">WORK</a>
                            </li>
                            <li >
                                <a className="btn-style nav-item nav-link" href="/projects">PROJECTS</a>
                            </li>
                            <li >
                                <a className="btn-style nav-item nav-link" href="/contact">CONTACT</a>
                            </li>
                        </ul>
                    </div>
                </div>

            </nav>

        </div>
)
}

export default Navbar;

Answer №1

For those looking to integrate Bootstrap with React seamlessly, I highly recommend checking out this resource - . I recently put together a small application and opted for this solution to sidestep any compatibility issues between Bootstrap and React.

Here's a snippet of the code I used:

import React, {Component} from "react";
import "./App.css";
import 'bootstrap/dist/css/bootstrap.min.css';

import MediaQuery from "react-responsive";
import SpotifyWebApi from "spotify-web-api-js";
import { Base64 } from 'js-base64';

import Jumbotron from 'react-bootstrap/Jumbotron'
import {Button} from 'react-bootstrap';
import Container from 'react-bootstrap/Container'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'


<div className="App">
                <Container>
                    <Row>
                            <Col className = "autoCenter">
                                <Jumbotron className = "backgroundColor">
                                  <h1>Hello, friend!</h1>
                                  <div>
                                    Hello
                                  </div>
                                  <div className = "mt3">
                                   text
                                  </div>
                                  <div>
                                    <Button
                                        className="spotifyGreen mt4 f6 dim br-pill"
                                        href = "">
                                            button
                                    </Button>
                                  </div>
                                </Jumbotron>
                            </Col>
                    </Row>
                </Container>
</div>

I omitted some details for brevity's sake, but I hope this snippet aids in understanding the syntax better!

Answer №2

My solution was to add the Jquery library to my index.js file. Surprisingly, react-bootstrap functioned properly even without the use of Jquery. Appreciate all the help!

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

Utilizing an overlay to conceal both the body content and the input fields

I have a website that includes a sliding overlay div which triggers when the user exits a specific area. To showcase this, I created a demonstration on jsfiddle. http://jsfiddle.net/qxcd8y1L/ <body class="overlay"> <input> </body> ...

Is there a way to send multiple actions to Node.js via a dropdown list using POST method?

I have encountered an issue where I am trying to include multiple actions in a single form within a dropdown list. However, I am only able to POST one action at a time. admin.html <form action="/start" method="post" id="tableForm"> <select id= ...

Synchronization problem with Apollo Client cache between multiple instances in a Next.js application using React Apollo and managed with pm2

Currently, I am utilizing Next.js and React Apollo for my application. To ensure optimal performance, I have configured my application to run with pm2 in a clustered mode featuring two instances. However, I have encountered an issue where switching user pr ...

CSS is not referred to as animation

Every time we hit a key, the dinosaur receives a jump class that should activate an animation. Unfortunately, the animation does not play. animation not functioning <!DOCTYPE html> <html lang="en"> <head> <meta c ...

Encountered an issue while trying to set up mocks with $route in vue-test-utils

I am currently practicing test referencing by using a mock router. Here is the code I am working with: NestedRoute.vue <template> <div> <div>Nested Route</div> <div class="username"> {{ $route.params.username ...

"Utilizing the __proto__ property in Express.js for handling request

One issue that I've encountered is with the request.body generated by the express.urlencoded() middleware. Sometimes, it adds "__proto__" at the end of the request.body object, which makes it impossible to directly use it to initialize a mongoose mode ...

Deactivate the other RadioButtons within an Asp.net RadioButtonList when one of them is chosen

Is there a way to disable other asp.net radio buttons when one of them is selected? I have three radio buttons, and I want to disable the other two when one is selected. After doing some research, I managed to disable the other two when the third one is se ...

Extract information from the table using $_POST

I possess a datatable within a form. Inside that table, there is a column designated for setting a price. Upon submitting the form on the same page, the $_POST data fails to populate. Consequently, I am in need of inserting it into the MySQL db post-submit ...

Create distinct 4-digit codes using a random and innovative method, without resorting to brute force techniques

I am working on developing an application that requires generating random and unique 4-digit codes. The range of possible codes is from 0000 to 9999, but each day the list is cleared, and I only need a few hundred new codes per day. This means it's fe ...

Function that wraps JSX elements with the ability to infer types through generics

At the moment, this function is functioning properly function wrapElement(elem: JSX.Element) { return ({ ...props }) => React.cloneElement(elem, { ...props }) } I've been using it in this way to benefit from intelliSense for tailwind classes con ...

What is the best way to call a method within a TypeScript class using its name as a string while already inside the class itself?

Currently, I am developing a class that automates the creation of routes for Express and invokes a function in a controller. However, upon trying to execute this[methodName](req, res), I come across an error message stating: 'Element implicitly has an ...

What is the best way to include a line break in a text sourced from a React state?

Here is a functional React code snippet: const about={ text1: 'Lorem, ipsum dolor sit amet consectetur adipisicing elit. Facere, qui?', text2: 'eligendi voluptates nesciunt quam dolor reiciendis dolorum voluptas? Labore, a pariatur?&apos ...

Having trouble getting the `nth-of-type` and `nth-child` selectors in CSS to function

I am attempting to apply a green color for the first nth child flag element <div id="axis"> <div class="super"></div> <div class="flag">flag 1</div><!-- I want this text to be green--> <div class="supe ...

Mastering the art of horizontal alignment in forms

So, within my render function, the following code is used: render() { <div> <form id="one"> <TextField id="t1" ... /> <Button id="b1" /> </form> <div id="empty"><div ...

Checking email existence through remote jQuery validation

Utilizing the jQuery validator plugin, I am implementing an ajax function with a remote method to validate whether an email already exists in my database. However, I am encountering an error when making the ajax call within my validation function. "email ...

Wordpress problem with Bootstrap JavaScript code involving data-toggle="collapse"

Currently facing an issue with my project. This is my first attempt at creating a WordPress blog, inspired by the HTML site www.humantools.com.mx and building a blog for it at www.humantools.com.mx/blog. There's a strange problem: when logged in, the ...

Display a single specific outcome within a React component's list

import {useState, useEffect } from 'react' import axios from 'axios' const Singlecountry = ({searchedCountries, setWeather, weather}) => { const weatherName = searchedCountries[0].capital console.log(weather) useEffect(() =&g ...

Having Trouble Choosing Options From Dropdown Menu Using Index in Selenium with Java

I am familiar with how to choose an element from a dropdown using the selectByIndex method. However, when attempting to use selectByIndex (select.selectByIndex(index)) on the HTML snippet below: <select id="destinationAllocationId" name="destinationAll ...

Transitioning from embedded browser to system browser in a Next.js / React.JS application

I'm currently dealing with an issue on my Next.js payment page and could really use some expertise. Here's the situation at hand: My payment page has a QR code that directs users to the payment page created with Next.js. When users scan this QR ...

"Encountering difficulties while trying to modify the QuillNoSSRWrapper value within a Reactjs

Currently, I am working on a project involving ReactJS and I have opted to use the Next.js framework. As of now, I am focused on implementing the "update module" (blog update) functionality with the editor component called QuillNoSSRWrapper. The issue I ...