Milad
Milad

Reputation: 53

TypeError: Cannot read property 'message' of undefined

I'm not sure why I'm getting this error. I'm copying the code directly as is from "Pure React" by Dave Ceddia. I'm working on the github-file-list project.

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'
    }
},
];

The error points to where I to the CommitMessage component where I declare {commit.message}.

Upvotes: 0

Views: 3692

Answers (1)

Cat_Enthusiast
Cat_Enthusiast

Reputation: 15688

Probably has something to do with this

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

lastestCommit, looks like a typo.

Upvotes: 1

Related Questions