1

I'm using React-Bootstrap to render a button group as an example, but it's refusing to render, and is instead telling me "ButtonGroup is undefined". I've installed the module via NPM and have imported it using ES6 (translated by babel). I'm exporting my components, to then eventually be rendered in my app as children.

import React, { Component, PropTypes } from 'react';
import Bootstrap from 'react-bootstrap';

export default class NavBar extends Component {
    render(){

    return(
     <Bootstrap.ButtonGroup>
    <Bootstrap.Button>1</Bootstrap.Button>
    <Bootstrap.Button>2</Bootstrap.Button>
    <Bootstrap.DropdownButton title="Dropdown" id="bg-nested-dropdown">
      <Bootstrap.MenuItem eventKey="1">Dropdown link</Bootstrap.MenuItem>
      <Bootstrap.MenuItem eventKey="2">Dropdown link</Bootstrap.MenuItem>
    </Bootstrap.DropdownButton>
  </Bootstrap.ButtonGroup>
    );
  }
}

2 Answers 2

4

There is a special way to import using ES6 based on the docs for 'react-bootstrap':

https://react-bootstrap.github.io/getting-started.html#es6

Es6 modules aren't supported natively yet, but you can use the syntax now with the help of a transpiler like Babel.

import Button from 'react-bootstrap/lib/Button';
// or
import { Button } from 'react-bootstrap';
Sign up to request clarification or add additional context in comments.

Comments

0

you also will want to bring in ButtonGroup from the react-bootstrap library like this.

import Button from 'react-bootstrap/lib/Button';
import ButtonGroup from 'react-bootstrap/lib/ButtonGroup';
// or
import { Button, ButtonGroup } from 'react-bootstrap';

Comments

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.