Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-bootstrap <Button> not working properly

So recently I decided to try and use the react-bootstrap library to make my code look simpler but for some reason the tag isn't working correctly.

I have this code with all the imports in my index.js file and the stylesheet import in my index.html

<Button variant="primary">Hello</Button>

This is what i used to create the button

enter image description here

I just don't get why it won't use the variant, and when I remove the variant tag it looks the same.

like image 388
John Morris Avatar asked Feb 24 '20 03:02

John Morris


3 Answers

By default btn btn-default class is added you need to override that class with className="btn-primary". This will fix your issue

   <Button variant="primary" className="btn-primary">Primary</Button>
like image 57
Ankush Kumar Avatar answered Oct 12 '22 01:10

Ankush Kumar


Check If you have installed Bootstrap in your node-modules.

Install it if haven't: npm install bootstrap

Use the below import on the .js file where <Button> component is being used:

import 'bootstrap/dist/css/bootstrap.min.css';
like image 38
laxmi kamath Avatar answered Oct 12 '22 00:10

laxmi kamath


I just faced this issue. Look for where the element is imported from. It should be imported from

import { Button } from 'react-bootstrap'

instead of

import { Button } from 'react'
like image 26
Bitan Debnath Avatar answered Oct 11 '22 23:10

Bitan Debnath