Chap03 -> Creating function-based component -> Children props
parent
dafd006124
commit
affd03b580
|
@ -1,13 +1,15 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { PageTitle } from './PageTitle';
|
||||||
|
import { Page } from './Page';
|
||||||
import { QuestionList } from './QuestionList';
|
import { QuestionList } from './QuestionList';
|
||||||
import { getUnansweredQuestions } from './QuestionsData';
|
import { getUnansweredQuestions } from './QuestionsData';
|
||||||
|
|
||||||
export const HomePage = () => (
|
export const HomePage = () => (
|
||||||
|
<Page>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<PageTitle>Unanswered Questions</PageTitle>
|
||||||
<h2>Unanswered Questions</h2>
|
|
||||||
<button>Ask a question</button>
|
<button>Ask a question</button>
|
||||||
</div>
|
</div>
|
||||||
<QuestionList data={getUnansweredQuestions()} />
|
<QuestionList data={getUnansweredQuestions()} />
|
||||||
</div>
|
</Page>
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { PageTitle } from './PageTitle';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
title?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Page = ({ title, children }: Props) => (
|
||||||
|
<div>
|
||||||
|
{title && <PageTitle>{title}</PageTitle>}
|
||||||
|
{children}
|
||||||
|
{/* Component nested within Page component will be rendere here */}
|
||||||
|
</div>
|
||||||
|
);
|
|
@ -0,0 +1,5 @@
|
||||||
|
import React from 'react';
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
export const PageTitle = ({ children }: Props) => <h2>{children}</h2>;
|
Loading…
Reference in New Issue