组件未显示在React中

时间:2017-10-26 00:46:31

标签: reactjs

我添加了一个组件来显示预先存在的代码中的注释类型,但它没有显示。知道为什么吗?我把它放在props对象中,并且在渲染代码中完全按照它应该呈现的方式引用它。我可能做错了什么?其余代码是FB文档中的一个示例,它可以正常工作。只有我的组件没有渲染。

    function formatDate(date) {
  return date.toLocaleDateString();
}

function Comment(props) {
  return (
    <div className="Comment">
      <div className="UserInfo">
        <img className="Avatar"
             src={props.author.avatarUrl}
             alt={props.author} />
        <div className="UserInfo-name">
          <h1>{props.author.naam}
          </h1>
        </div>
      </div>
      <div className="Comment-text">
        {props.text}
      </div>
      <div className="Comment-type">
        {props.type}
      </div>
      <div className="Comment-date">
        {formatDate(props.date)}
      </div>
    </div>
  );
}

const comment = {
  date: new Date(),
  text: 'I hope you enjoy learning React seriously!',
  type: 'Positive',
  author: {
    naam: 'Hello Kitty',
    avatarUrl: 'http://placekitten.com/g/64/64'
  }
};
ReactDOM.render(
  <Comment
    date={comment.date}
    text={comment.text}
    author={comment.author} />,
  document.getElementById('root')
);

0 个答案:

没有答案