1

I have installed react-bootstrap with npm (npm install react-bootstrap --save) but my code is not rendering on the browser. The page is just blank. I use webpack for builds and babel for transpilation. Below is my react code.

import React from 'react'
import ReactDOM from 'react-dom'
import ReactBootstrap from 'react-bootstrap'

const buttonsInstance = (
  <ButtonToolbar>
    <Button bsStyle="primary" bsSize="large" active>Primary button</Button>
    <Button bsSize="large" active>Button</Button>
  </ButtonToolbar>
);

ReactDOM.render(buttonsInstance, document.getElementById('root'));

Thanks!

1 Answer 1

3

Import the controls you'll use explicitly:

import React from 'react'
import ReactDOM from 'react-dom'
import {ButtonToolbar, Button} from 'react-bootstrap' // define individual controls to import    
const buttonsInstance = (
  <ButtonToolbar>
    <Button bsStyle="primary" bsSize="large" active>Primary button</Button>
    <Button bsSize="large" active>Button</Button>
  </ButtonToolbar>
);

ReactDOM.render(buttonsInstance, document.getElementById('root'));
Sign up to request clarification or add additional context in comments.

5 Comments

Good job Johnny. If you're unfamiliar with import syntax here (i.e. using curly brackets {} ) then checkout Destructuring.
How exactly will i apply that??
Well it's just FYI - ES6 destructuring if you want to understand what {Button} actually means. It won't affect your example but might make you a better dev!
Tried something like this: import {ButtonToolbar: BtnBar, Button: Btn} from 'react-bootstrap' and substituted them in their respective tags but did not work. Maybe i am not doing it properly.
Try `import { Button as Btn } from 'react-bootstrap'. Your syntax is correct for es6 objects in general but when importing try the aforementioned if you want to use aliases. Checkout mdn

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.