TypeError:无法读取未定义的属性“消息”

时间:2019-01-06 05:54:11

标签: javascript reactjs

我不确定为什么会出现此错误。我直接复制了Dave Ceddia的“ Pure React”中的代码。我正在github-file-list项目上。

const FileListItem = ({ file }) => (
    <tr className="file-list-item">
        <FileName file={file} />
        <CommitMessage
            commit={file.lastestCommit} />
    </tr>
);
FileListItem.propTypes = {
    file: PropTypes.object.isRequired
};

const CommitMessage = ({ commit }) => (
    <td className="commit-message">
        {commit.message}
    </td>
); 
CommitMessage.propTypes = {
    commit: PropTypes.object.isRequired
};

const testFiles = [
{
    id: 1,
    name: 'src',
    type: 'folder',
    updated_at: '2016-07-11 21:24:00',
    latestCommit: {
        message: 'Initial commit'
    }
},
{
    id: 2,
    name: 'tests',
    type: 'folder',
    updated_at: "2016-07-11 21:24:00",
    latestCommit: {
        message: 'Initial commit'
    }
}, {
    id: 3,
    name: 'README',
    type: 'file',
    updated_at: "2016-07-18 21:24:00",
    latestCommit: {
        message: 'Added a readme'
    }
},
];

错误指向我声明{commit.message}的CommitMessage组件。

1 个答案:

答案 0 :(得分:1)

可能与此有关

const FileListItem = ({ file }) => (
    <tr className="file-list-item">
        <FileName file={file} />
        <CommitMessage
            commit={file.lastestCommit} />
    </tr>
);

lastestCommit,看起来像是一个错字。