Chap03 -> Creating function-based components -> Creating mock data
parent
f0492816c5
commit
2d0e56055c
|
@ -0,0 +1,53 @@
|
||||||
|
export interface QuestionData {
|
||||||
|
questionId: number;
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
userName: string;
|
||||||
|
created: Date;
|
||||||
|
answers: AnswerData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AnswerData {
|
||||||
|
answertId: number;
|
||||||
|
content: string;
|
||||||
|
userName: string;
|
||||||
|
created: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
const questions: QuestionData[] = [
|
||||||
|
{
|
||||||
|
questionId: 1,
|
||||||
|
title: 'Why should I learn TypeScript?',
|
||||||
|
content:
|
||||||
|
'TypeScript seems to be getting popular so I wonder whether it is worth my time learning it? What benefits does it give over JavaScript?',
|
||||||
|
userName: 'Bob',
|
||||||
|
created: new Date(),
|
||||||
|
answers: [
|
||||||
|
{
|
||||||
|
answertId: 1,
|
||||||
|
content: 'To catch problems earlier speeding up your development',
|
||||||
|
userName: 'Jane',
|
||||||
|
created: new Date(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
answertId: 2,
|
||||||
|
content: 'So, that you can use the JS features of tomorrow, today',
|
||||||
|
userName: 'Fred',
|
||||||
|
created: new Date(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
questionId: 2,
|
||||||
|
title: 'Which state management tool should I use?',
|
||||||
|
content:
|
||||||
|
'There seem to be a fair few state management tools around for React - React, Unstated, ... Which one should I use?',
|
||||||
|
userName: 'Bob',
|
||||||
|
created: new Date(),
|
||||||
|
answers: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const getUnansweredQuestions = (): QuestionData[] => {
|
||||||
|
return questions.filter((q) => q.answers.length === 0);
|
||||||
|
};
|
Loading…
Reference in New Issue