Chap03 -> Creating function-based components -> Optional and default props

Chap03
Jason Zhu 2022-03-26 00:16:30 +11:00
parent 851a26d1b9
commit dafd006124
1 changed files with 13 additions and 1 deletions

View File

@ -3,11 +3,19 @@ import { QuestionData } from './QuestionsData';
interface Props {
data: QuestionData;
showContent?: boolean;
}
export const Question = ({ data }: Props) => (
export const Question = ({ data, showContent }: Props) => (
<div>
<div>{data.title}</div>
{showContent && (
<div>
{data.content.length > 50
? `${data.content.substring(0, 50)}`
: data.content}
</div>
)}
<div>
{`Ask by ${
data.userName
@ -15,3 +23,7 @@ export const Question = ({ data }: Props) => (
</div>
</div>
);
Question.defaultProps = {
showContent: true,
};