React Native

Forms & Validation

React Hook Form, Formik, Yup validation, controlled vs uncontrolled inputs, error handling

18 câu hỏi phỏng vấn·
Mid-Level
1

What is the main difference between a controlled and an uncontrolled input in React Native?

Câu trả lời

A controlled input is managed by React state via value and onChangeText props, allowing full control over the value at any time. An uncontrolled input uses a ref to directly access the DOM value without going through React state. Controlled inputs are recommended as they facilitate real-time validation and synchronization with the application state.

2

Which React Hook Form hook is used to register an input and handle its validation?

Câu trả lời

The useForm hook from React Hook Form returns an object containing several methods and properties. The register method allows registering an input in the form and attaching validation rules to it. It returns the necessary props (onChange, onBlur, ref) to connect the input to the form management system.

3

How to define an email validation schema with Yup?

Câu trả lời

Yup uses a chainable API to define validation schemas. To validate an email, use yup.string() to define the type, then chain .email() for email format validation, and optionally .required() to make the field mandatory. This declarative approach allows creating readable and reusable validations.

4

In Formik, which prop is used to define the initial values of the form?

5

What is the main performance advantage of React Hook Form compared to Formik?

+15 câu hỏi phỏng vấn

Nắm vững React Native cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí