강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

아침에사과님의 프로필 이미지
아침에사과

작성한 질문수

[리뉴얼] React로 NodeBird SNS 만들기

다이나믹 라우팅

TypeError: Cannot read property 'Likers' of null

작성

·

174

0

강사님 깃허브 ch6 내용과 이것저것 비교해봤지만 뭐가 원인인지 잘 모르겠습니다. 구조가 너무 복잡해서 찾기도 쉽지 않네요.

도움 부탁드립니다.

https://github.com/Yohan-K/react-nodebird

// GET /posts/1
router.get('/:postId', async (req, res, next) => {
try {
const post = await Post.findOne({
where: {id: req.params.postId},
include: [{
model: User,
attributes: ['id', 'nickname'],
}, {
model: Image,
}, {
model: Comment,
include: [{
model: User,
attributes: ['id', 'nickname'],
order: [['createdAt', 'DESC']],
}],
}, {
model: User,
as: 'Likers',
attributes: ['id'],
}],
});
res.status(200).json(post);
} catch
(error) {
console.error(error);
next(error);
}
});
 

답변 1

1

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

PostCard에 들어오는 post가 undefined인 것입니다. post가 왜 undefined인지 추적해보아야 합니다.

<PostCard post={post}  /> 하고 있는 곳으로 가서 post가 왜 undefined인지 찾아보세요. 

아침에사과님의 프로필 이미지
아침에사과

작성한 질문수

질문하기