Working with Forms Flashcards

1
Q

What are controlled fields in React forms?

A

Fields with values stored in state, requiring more code, and potentially causing performance issues due to re-renders on input.

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

What are the performance issues of controlled fields in React forms?

A

Re-renders on every character input, which can be significant in large forms.

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

What are uncontrolled fields in React forms?

A

Fields where values are not controlled by state, and values are retrieved using browser’s native features.

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

What is the purpose of the name attribute in uncontrolled fields?

A

It extracts field values in the form submit handler.

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

What is the role of the onSubmit event in React forms?

A

It is triggered when the form is submitted.

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

What is FormData in React?

A

An interface to access form values, using the form element as its constructor input.

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

What is React Hook Form used for?

A

It is a library for handling forms in React, providing hooks and state management for form data.

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

What does the useForm hook return in React Hook Form?

A

It returns functions and state, including validation and submission status, with a generic type parameter for form data.

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

What does the register function in React Hook Form do?

A

It registers a field with the form, handling field values, focus, and validation, and spreading handlers on the field editor.

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

How can you specify validation in React Hook Form?

A

By passing validation rules as options to the register function, including custom error messages.

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

How do you obtain validation errors in React Hook Form?

A

By accessing the errors state returned by useForm, which contains field-specific error messages.

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

What does handleSubmit do in React Hook Form?

A

It handles form submission after validation, calling the provided function on successful validation.

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

What does the isSubmitting state in React Hook Form indicate?

A

It indicates whether the form is currently being submitted, useful for disabling form elements during submission.

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

What is the purpose of isSubmitSuccessful in React Hook Form?

A

It allows you to conditionally render a success message when the form submission is successful.

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