December 2019
Intermediate to advanced
598 pages
12h 21m
English
Let's carry out the following steps to implement submission on the ask form:
export interface PostQuestionData { title: string; content: string; userName: string; created: Date;}export const postQuestion = async ( question: PostQuestionData,): Promise<QuestionData | undefined> => { await wait(500); const questionId = Math.max(...questions.map(q => q.questionId)) + 1; const newQuestion: QuestionData = { ...question, questionId, answers: [], }; questions.push(newQuestion); return newQuestion;};
The function adds the question to the questions array using the Math.max method to set questionId to the next number.
Read now
Unlock full access