React-Form-Controls Flashcards

1
Q

How do controlled components differ from uncontrolled components?

A

For controlled elements, React takes control of the form data and maintains the state of the form element. The component decides when and how to update the state, and it re-renders itself based on the state changes.

For uncontrolled elements, a form element in a component is controlled by the DOM. The DOM decides the state of the input element and updates it based on a user’s input.

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

What are some advantages of using uncontrolled components?

A

For uncontrolled elements, a form element in a component is controlled by the DOM. The DOM decides the state of the input element and updates it based on a user’s input.

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

What are some advantages of using controlled components?

A

The UI and the data are in sync
Form data can be passed between different components

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

Which style do you prefer?

A

Controled components as they are easier to access the form data where you can just access the input values by the state variable associated with it

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

What two props must you pass to an input for it to be “controlled”?

A

value and onChange

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

What are some popular npm packages for creating forms in React?

A

React Hook Form, Formik, React Final

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