Reactstrap卡组件抛出错误

时间:2017-12-06 16:54:10

标签: reactjs reactstrap

问题在于反应卡:https://reactstrap.github.io/components/card/

使用像Card等的反应堆组件不起作用。

组件:版本I

import React, { Component } from 'react';
import { Card, Button, CardImg, CardTitle, CardText, CardDeck, CardSubtitle, CardBody } from 'reactstrap';

class MoviesIndex extends Component {

    render() {
        return (
            <CardDeck>
                <Card>
                    <CardImg top width="100%" src="" alt="Movie Poster" />
                </Card>
            </CardDeck>
        );
    }
}

export default MoviesIndex;

输出 *工作正常,没有任何错误。

但是当我尝试使用reactstrap中的其余组件时。它会在控制台上抛出错误。

组件:版本II

import React, { Component } from 'react';
import { Card, Button, CardImg, CardTitle, CardText, CardDeck, CardSubtitle, CardBody } from 'reactstrap';

class MoviesIndex extends Component {

    render() {
        return (
            <CardDeck>
                <Card>
                    <CardImg top width="100%" src="" alt="Movie Poster" />
                    <CardBody>
                        <CardTitle>Card title</CardTitle>
                        <CardSubtitle>Card subtitle</CardSubtitle>
                        <CardText>This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</CardText>
                        <Button>Button</Button>
                    </CardBody>
                </Card>
            </CardDeck>
        );
    }
}

export default MoviesIndex;

输出: enter image description here

的package.json

{
  "name": "client",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch"
  },
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "jquery": "^2.2.1",
    "jsdom": "^8.1.0",
    "mocha": "^2.4.5",
    "react-addons-test-utils": "^0.14.7",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "axios": "^0.17.1",
    "babel-preset-stage-1": "^6.1.18",
    "lodash": "^3.10.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-transition-group": "^2.2.1",
    "reactstrap": "^4.8.0",
    "redux": "^3.7.2",
    "redux-promise": "^0.5.3"
  }
}

我无法调试此问题。请帮忙! TIA。

2 个答案:

答案 0 :(得分:2)

v4.8.0中没有CardBody等组件。

升级到最新版本(reactstrap v5.0.0-alpha.4)可以解决此问题!

npm install --save reactstrap@5.0.0-alpha.4

有关详细信息,请参阅我在reactstrap @ github上创建的问题: https://github.com/reactstrap/reactstrap/issues/730

答案 1 :(得分:0)

这看起来像是一个错字:

renderMovies() {
        return _.map(this.props.movies, movie => {

缺少)

尝试

_.map(this.props.movies, movie) => {

如果不这样做,请将console.log()放在所有内容之后,以查看它变为undefined的位置。

这种类型的错误通常是由于某些内容未正确导出或由于数据丢失而导致null / undefined等原因造成的。

这是我推荐使用ES Lint的好机会,因此您可以从被动显示的错误中获得额外的帮助。如果您没有使用它,请查看它。它绝对值得研究和使用。

我不会在这里推荐任何特定的linting配置。这超出了这个帮助的范围。 ES Lint会强调代码错误,例如缺少)的红色下划线,因此您将体验到更少的此类错误:)