React Native

Forms & Validation

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

18 interview questions·
Mid-Level
1

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

Answer

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?

Answer

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?

Answer

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 interview questions

Master React Native for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free