0

I am using reactJS with Bottstrap. I am trying to put user image and with drodown. so when user click on dropdown the the dropdown will open.

My dropdown is not working.

Here is my code. :

    <div class="dropdown">
   <a href="#" data-toggle="dropdown" class="nav-item nav-link dropdown-toggle user-action">
   <img class = "loginImage" src="https://someImage" class="bi bi-person" alt="Avatar"></img>
   </a> 
   <ul class="dropdown-menu">
      <li>
         <a href="#" class="dropdown-item"> Profile A</a>
      </li>
      <li>
         <a href="#" class="dropdown-item"> Profile B</a>
      </li>
      <li>
         <a href="#" class="dropdown-item"> Profile C</a>
      </li>
      <li>
         <a href="#" class="dropdown-item">Profile D</a>
      </li>
   </ul>
</div>

Any help here or any other way to implement this.

My Dependency :

    "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.35",
    "@fortawesome/free-solid-svg-icons": "^5.15.3",
    "@fortawesome/react-fontawesome": "^0.1.14",
    "@popperjs/core": "^2.9.2",
    "@testing-library/jest-dom": "^5.13.0",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "axios": "^0.21.1",
    "bootstrap": "^5.0.1",
    "bootstrap-icons": "^1.5.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-popper": "^2.2.5",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.2"
  },
5
  • 1
    did you add jquery as dependency? Commented Jun 24, 2021 at 5:57
  • let me upload my packgae json Commented Jun 24, 2021 at 5:58
  • @Apostolos NO. I haven't Commented Jun 24, 2021 at 6:00
  • @Apostolos one quixk questio, how u sure that this code is from version 3. Because i am using code from bootstrap 5 only from this page. getbootstrap.com/docs/5.0/components/dropdowns Commented Jun 24, 2021 at 6:20
  • 1
    check my answer :) Commented Jun 24, 2021 at 6:29

1 Answer 1

3

In order for the dropdown to work with bootstrap, you need to import @popperjs/core dependency.

bootsrap 5 has dropped dep on jquery so there is no need anymore to import jquery

Check my sandbox

Sign up to request clarification or add additional context in comments.

10 Comments

Nope no luck for me even after adding @popperjs/core
you need to import bootstrap and popper. check the sandbox and the imports.
import "bootstrap/dist/css/bootstrap.min.css"; import "@popperjs/core"; import "bootstrap";
I have run this command in my terminal npm i react-popper @popperjs/core I have updated the dependency in question. correct me if i m wrong. I m new in reactJS
didnt quite understand. you mean to add an image instead of text? you can easily add an iomage of height e.g. 40px and then apply the equivalent css to remove the background from the container div
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.