Chap05 -> Using route parameters -> Implementing more of the question page -> 5. call getQuestion function during initial render
parent
de5e78e621
commit
a2f0fb0522
|
@ -11,5 +11,14 @@ import { QuestionData, getQuestion } from './QuestionsData';
|
||||||
export const QuestionPage = () => {
|
export const QuestionPage = () => {
|
||||||
const [question, setQuestion] = React.useState<QuestionData | null>(null);
|
const [question, setQuestion] = React.useState<QuestionData | null>(null);
|
||||||
const { questionId } = useParams();
|
const { questionId } = useParams();
|
||||||
|
React.useEffect(() => {
|
||||||
|
const doGetQuestion = async (questionId: number) => {
|
||||||
|
const foundQuestion = await getQuestion(questionId);
|
||||||
|
setQuestion(foundQuestion);
|
||||||
|
};
|
||||||
|
if (questionId) {
|
||||||
|
doGetQuestion(Number(questionId));
|
||||||
|
}
|
||||||
|
}, [questionId]);
|
||||||
return <Page>Question Page {questionId}</Page>;
|
return <Page>Question Page {questionId}</Page>;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue