Implementing Forms in React Flashcards

1
Q

What is the main purpose of forms?

A

Collect input from user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the main button a form has?

A

submit button

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a controlled form?

A

Is the most common approach: all the state is controlled by react and thus is the single source of truth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a uncontrolled form?

A

The DOM maintains the state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 5 events triggered on every user interaction with a form (e.g: type a key)

A

1 - The form is initialized with the initial state
2 - The form renders the initial state
3 - User input triggers onChange callback with a new value
4 - onChange callback updates the state of the form (setState)
5 - Component re-renders (due to step 4 setState).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the 3 advantages of controlled forms?

A

Instant feedback, disable portions of the ui conditionally, format user input

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When to add form validation so the whole form is validated when the user clicks on submit?

A

in the onSubmit event of the form element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are two disadvantages of vanilla React form?

A

verbose and error prone

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Formik?

A

A library that allow creating forms. Fixes the verboseness and error-proneness of Vanilla React and provides other important features.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the main features of Formik?

A

Automatically keeps track of values, errors and visited fields. Allow easy validations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the four components of Formik?

A

Formik, Form, Field and ErrorMessage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the three state variables that Formik provides?

A

map of Field and input field value. Map of Field and errors. Map of Field and boolean to indicate if the field was ever touched.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the most important attribute of the Field element? Why?

A

the ‘name’ attribute. Because that’s how formik and the developer know how to access data related to that input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly