...
/Implementing Form Submission in the Answer Form
Implementing Form Submission in the Answer Form
Learn to implement the submission form in the answer form.
We'll cover the following...
Carry out the following steps to implement form submission in the answer form:
In
QuestionsData.ts
, create a function that simulates posting an answer:
Press + to interact
export interface PostAnswerData {questionId: number;content: string;userName: string;created: Date;}export const postAnswer = async (answer: PostAnswerData,): Promise<AnswerData | undefined> => {await wait(500);const question = questions.filter(q => q.questionId === answer.questionId,)[0];const answerInQuestion: AnswerData = {answerId: 99,...answer,};question.answers.push(answerInQuestion);return answerInQuestion;};
The function finds the question in the questions
array and adds the answer to it. The remainder of the preceding code contains straightforward types for the answer to post and the function’s result.
In ...