Chap05 -> Using route parameters -> Implementing more of the question page -> 5. call getQuestion function during initial render
parent
a51437c7cc
commit
f50dd73596
|
@ -11,5 +11,14 @@ import { QuestionData, getQuestion } from './QuestionsData';
|
|||
export const QuestionPage = () => {
|
||||
const [question, setQuestion] = React.useState<QuestionData | null>(null);
|
||||
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>;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue