Chap03 -> Creating function-based components -> Creating HomePage child components
This commit is contained in:
parent
d54f501934
commit
851a26d1b9
@ -1,4 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { QuestionList } from './QuestionList';
|
||||||
|
import { getUnansweredQuestions } from './QuestionsData';
|
||||||
|
|
||||||
export const HomePage = () => (
|
export const HomePage = () => (
|
||||||
<div>
|
<div>
|
||||||
@ -6,5 +8,6 @@ export const HomePage = () => (
|
|||||||
<h2>Unanswered Questions</h2>
|
<h2>Unanswered Questions</h2>
|
||||||
<button>Ask a question</button>
|
<button>Ask a question</button>
|
||||||
</div>
|
</div>
|
||||||
|
<QuestionList data={getUnansweredQuestions()} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
17
QandA/frontend/src/Question.tsx
Normal file
17
QandA/frontend/src/Question.tsx
Normal 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>
|
||||||
|
);
|
@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { Question } from './Question';
|
||||||
import { QuestionData } from './QuestionsData';
|
import { QuestionData } from './QuestionsData';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -8,7 +9,9 @@ interface Props {
|
|||||||
export const QuestionList = ({ data }: Props) => (
|
export const QuestionList = ({ data }: Props) => (
|
||||||
<ul>
|
<ul>
|
||||||
{data.map((question) => (
|
{data.map((question) => (
|
||||||
<li key={question.questionId}></li>
|
<li key={question.questionId}>
|
||||||
|
<Question data={question} />
|
||||||
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user