1

I'm trying to test out the carousel but when I load the page it is blank.

I installed react bootstrap with npm.

The carousal code is from https://react-bootstrap.github.io/components.html#media-content. I looked at my web console and I don't have any warnings or errors either.

carousal.js

import React, { Component } from 'react';
import {Carousel} from 'react-bootstrap';
class carousel extends Component {
    render() {
        return (
            <Carousel>
                <Carousel.Item>
                    <img width={900} height={500} alt="900x500" src={require('./images/cs_logo.png')}/>
                    <Carousel.Caption>
                        <h3>First slide label</h3>
                        <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
                    </Carousel.Caption>
                </Carousel.Item>
                <Carousel.Item>
                    <img width={900} height={500} alt="900x500" src={require('./images/cs_logo.png')}/>
                    <Carousel.Caption>
                        <h3>Second slide label</h3>
                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                    </Carousel.Caption>
                </Carousel.Item>
                <Carousel.Item>
                    <img width={900} height={500} alt="900x500" src={require('./images/cs_logo.png')}/>
                    <Carousel.Caption>
                        <h3>Third slide label</h3>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
                    </Carousel.Caption>
                </Carousel.Item>
            </Carousel>
        );
    }
}

export default carousel;

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import carousel from './carousal';

ReactDOM.render(<carousel/>,document.getElementById('root'));

index.html

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">  
    <title>title</title>
</head>

<body>
<header>
<div id="nav"></div>
</header>
<div id="root" style="text-align: center; float: none"></div>
</body>

</html>

4 Answers 4

1

Did you include js files to html file?

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.30.6/react-bootstrap.js" > </srcipt>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.30.6/react-bootstrap.js" > </srcipt>
Sign up to request clarification or add additional context in comments.

1 Comment

I tried adding it and now I get this error in console "react-bootstrap.js:2037 Uncaught TypeError: Cannot read property 'PropTypes' of undefined(…)exports.__esModule @ react-bootstrap.js:2037__webpack_require__ @ react-bootstrap.js:30exports.__esModule @ react-bootstrap.js:430__webpack_require__ @ react-bootstrap.js:30exports.__esModule @ react-bootstrap.js:62__webpack_require__ @ react-bootstrap.js:30exports.__esModule @ react-bootstrap.js:50(anonymous function) @ react-bootstrap.js:53webpackUniversalModuleDefinition @ react-bootstrap.js:9(anonymous function) @ react-bootstrap.js:10"
1

Add this in index.js file

import 'bootstrap/dist/css/bootstrap.css';

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

Found the solution. It is not Bootstrap related but rather how I was exporting and naming my components.

Components need to capitalized as stated here. Simple React component not rendering

Comments

0

Add the CDN link in index.html. Although you found it this would help others.

<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous"/>

or add this in app.css

@import "bootstrap/dist/css/bootstrap.css";

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.