Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-bootstrap and Panel.Body

I'm new to React, so maybe I'm missing something here, but I want to use the Panel component from react-bootstrap. I'm following the documentation, but getting the following behavior.

This code works:

import { Panel } from 'react-bootstrap';

(...)

return ( # This is inside my component's render()
    <Panel>
        Foo
    </Panel>
)

This code doesn't work:

import { Panel } from 'react-bootstrap';

(...)

return ( # This is inside my component's render()
    <Panel>
        <Panel.Body>Foo</Panel.Body>
    </Panel>
)

The error says: Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of (ComponentName).

What am I doing wrong? Many thanks!

react 15.6.2, react-bootstrap 0.31.5

like image 629
petr Avatar asked Jan 18 '18 11:01

petr


People also ask

What are Bootstrap react panels?

React Bootstrap 5 Panels - examples & tutorial. Bootstrap React panels are bordered boxes where you can place texts, lists, tables and other content. Panels are similar to cards, but they don't include media. Panels are built with as little markup and styles as possible, but still manage to deliver a ton of control and customization.

What is a panel in Bootstrap?

A panel in bootstrap is a bordered box with some padding around its content: Panels are created with the .panel class, and content inside the panel has a .panel-body class: The .panel-default class is used to style the color of the panel. See the last example on this page for more contextual classes.

Why is my react-bootstrap API not working?

It was in the particular version of react-bootstrap, we were using 0.31.5 and you used 0.32, so that directed me to the cause of the problem. Apparently react-bootstrap 's API was changed between the versions.

What is the React component model?

The React component model gives us more control over form and function of each component. Each component is implemented with accessibility in mind. The result is a set of accessible-by-default components, over what is possible from plain Bootstrap.


1 Answers

Please change to:
import Panel from 'react-bootstrap/lib/Panel'

When importing from react-bootstrap you need to import the component from the lib folder.

like image 78
Nir Ben-Yair Avatar answered Sep 23 '22 00:09

Nir Ben-Yair