Chap03 -> Creating function-based components -> Creating HomePage child components

This commit is contained in:
Jason Zhu 2022-03-26 00:08:00 +11:00
parent d54f501934
commit 851a26d1b9
3 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,6 @@
import React from 'react';
import { QuestionList } from './QuestionList';
import { getUnansweredQuestions } from './QuestionsData';
export const HomePage = () => (
<div>
@ -6,5 +8,6 @@ export const HomePage = () => (
<h2>Unanswered Questions</h2>
<button>Ask a question</button>
</div>
<QuestionList data={getUnansweredQuestions()} />
</div>
);

View File

@ -0,0 +1,17 @@
import React from 'react';
import { QuestionData } from './QuestionsData';
interface Props {
data: QuestionData;
}
export const Question = ({ data }: Props) => (
<div>
<div>{data.title}</div>
<div>
{`Ask by ${
data.userName
} on ${data.created.toLocaleDateString()} ${data.created.toLocaleTimeString()}`}
</div>
</div>
);

View File

@ -1,4 +1,5 @@
import React from 'react';
import { Question } from './Question';
import { QuestionData } from './QuestionsData';
interface Props {
@ -8,7 +9,9 @@ interface Props {
export const QuestionList = ({ data }: Props) => (
<ul>
{data.map((question) => (
<li key={question.questionId}></li>
<li key={question.questionId}>
<Question data={question} />
</li>
))}
</ul>
);