:
const RecordCard = props => {
return (
<div className="record-container">
<RecordDate type={props.type} date={props.recordDateSlug} />
<RecordHead linkId={props.recordIdHash} title={props.title} category={props.category.categoryName} user={props.synotate_user.fullNameSlug} picture={props.synotate_user.picture} dataDate={props.dataDateRangeSlug}/>
<hr />
<RecordBody discovery={props.discovery} />
<RecordFooter reports={props.record_reports} files={props.record_files}/>
<EditRecord linkId={props.recordIdHash} recordUser={props.user} user={props.user.userId} />
<hr />
</div>
)
}
私category={props.category.categoryName}
はのエラーがスローされます。 category
だけ不定となり、エラーをスローしません、それがなかった場合は空のオブジェクトをデフォルトとし、その後categoryName
ます:
const RecordCard = ({
category: {
categoryName
} = {},
synotate_user: {
fullNameSlug,
picture
} = {},
user,
dataDateRangeSlug,
title,
recordIdHash,
type,
recordDateSlug,
discovery,
record_reports,
record_files
}) => {
const {
userId
} = user;
return (
<div className="record-container">
<RecordDate type={type} date={recordDateSlug} />
<RecordHead linkId={recordIdHash} title={title} category={categoryName} user={fullNameSlug} picture={picture} dataDate={dataDateRangeSlug}/>
<hr />
<RecordBody discovery={discovery} />
<RecordFooter reports={record_reports} files={record_files}/>
<EditRecord linkId={recordIdHash} recordUser={user} user={userId} />
<hr />
</div>
);
}
は勧告をありがとうございました。あなたの答えに基づいて、値が存在する場合、ブランク値を置き換えるために 'props'をどのように渡すのですか?私。マップされたオブジェクトを 'RecordCard'に渡しています。これは' RecordCard'をビルドするときの 'props'です。 – cphill