错误表明未指定prop

时间:2016-05-30 22:42:47

标签: javascript meteor reactjs ecmascript-6

我试图制作与todos应用程序非常相似的东西,以了解反应如何与流星一起工作。

我目前的代码如下:

BoardContainer.jsx

import { Meteor } from 'meteor/meteor';
import { Boards } from '../../api/boards/boards.js';
import { createContainer } from 'meteor/react-meteor-data';
import BoardPage from '../pages/BoardPage.jsx';

export default BoardContainer = createContainer(({ params }) => {
  const { id } = params;
  const board = Boards.findOne(id);

  return {
    board,
    boards: Boards.find({}).fetch(),
  };
}, BoardPage);

BoardPage.jsx

import React, { Component, PropTypes } from 'react';
import BoardList from '../components/BoardList.jsx';

export default class BoardPage extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    const { board, boards } = this.props;

    return (
      <main id="page">
        <BoardList boards={boards} />

        <div id="board">
          <h1>{board.name}</h1>
        </div>
      </main>
    );
  }
}

BoardPage.propTypes = {
  board: PropTypes.object.isRequired,
  boards: PropTypes.array,
};

BoardPage.contextTypes = {
  router: PropTypes.object,
};

电路板页面无法加载并出现以下错误:&#34;警告:失败propType:必需的prop&#39; board&#39;未在&#39; BoardPage&#39;中指定。检查&#39; MeteorDataContainer&#39;的渲染方法,&#34;以及&#34; Uncaught TypeError:无法读取属性&#39; name&#39;未定义的。&#34;

不确定为什么会抛出此错误,因为我认为我在容器文件中正确定义了它。

0 个答案:

没有答案