Bug with Bootstrap Collapse in combination with Bootstrap Toast - ReactJS
See original GitHub issueHi,
I think I may have found a bug between the Bootstrap v5.1.3 collapse feature and Toast-Messages in ReactJS
Setup to replicate the error:
Create a default react project with:
npx create-react-app collapse-toast-test
- Import boostrap with
npm i bootstrap
oryarn i bootstrap
- In
index.js
import bootstrap:
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/js/bootstrap.bundle.js';
- Use buttons from example: https://getbootstrap.com/docs/5.1/components/collapse/ and paste the code into
app.js
- In
app.js
import Toast (and make use of it if you want)
import { Toast } from "bootstrap";
Result:
Pressing the buttons only shows the hidden elements. Hide afterwards is not working. So the toggle-feature is bugged.
Used versions:
React-Version: 18.0.0 Bootstrap-Version: 5.1.3
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
React-Bootstrap Collapse is not working - Stack Overflow
Started using React-Bootstrap today and I want to make a collapsable card. Using Collapse component but it's not working. Any tips? My code:...
Read more >JavaScript · Bootstrap v5.2
Both Bootstrap and the framework may attempt to mutate the same DOM element, resulting in bugs like dropdowns that are stuck in the...
Read more >react-bootstrap | Yarn - Package Manager
Bootstrap compatibility React-Bootstrap is compatible with various versions of Bootstrap. As such, you need to ensure you are using the correct combination of ......
Read more >Toast - dbc docs - Dash Bootstrap Components
Icons and dismissing ... You can use the icon argument to add a contextually coloured icon to the header. You can also add...
Read more >Bootstrap Reactstrap Collapse is not working with list of ...
import React, { useState } from "react"; import { Card, CardText } from "reactstrap"; function Story(props) { console.log(props) return ( <Card ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another workaround is to import
Toast
directly fromtoast.js
import Toast from 'bootstrap/js/dist/toast.js';
The bug you are seeing has nothing to do with React, and almost nothing to do with bootstrap either. Rather, it’s your improper import of bootstraps javascript. You are explicitly importing bootstrap’s umd file (bundled with popper… but that irrelevant here), then importing the
Toast
class from bootstraps default path… which in the case of the bundler increate-react-app
is going to be the module path, ie bootstraps esm file. This effectively loads certain parts of bootstraps code base twice and you are seeing the effects of this.So instead of
You’ll want
The
import 'bootstrap';
is equivalent toimport 'bootstrap/dist/js/bootstrap.esm';
in this case - though I would not recommend the long hand import. Use the default and let your bundler decide what kind of files it wants.Note: You will need to make sure popper is installed as well - as you would no longer be loading the “bootstrap bundle” file that included everything in 1 file.