React Native

Forms & Validation

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

18 domande da colloquio·
Mid-Level
1

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

Risposta

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?

Risposta

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?

Risposta

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 domande da colloquio

Padroneggia React Native per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis