How do uncontrolled components in React handle form data?
Explanation:
Uncontrolled components in React don't rely on the component's state for form data. Instead, they use refs to directly interact with the DOM, allowing you to extract values when needed.
What's the difference between JSX attributes and HTML attributes?
Explanation:
While they serve similar purposes, JSX enforces camelCase naming convention for attributes to align with JavaScript's conventions.
Which of the following is a common approach for implementing form validation in React?
Explanation:
React provides flexibility in implementing form validation. You can leverage HTML5's built-in validation, create custom functions tailored to your application, or use dedicated libraries for more complex scenarios.
In JSX, how would you set the 'class' attribute for an element?
Explanation:
Since 'class' is a reserved keyword in JavaScript, JSX uses 'className' to set the CSS class of an element.
When a component's state or props change, React decides whether to update the actual DOM. What is this process called?
Explanation:
React uses a Virtual DOM, a lightweight representation of the actual DOM. When state or props change, React performs a diffing algorithm on the Virtual DOM. This process identifies the minimal changes needed, optimizing updates to the real DOM for performance.
What is the correct syntax for a functional component in React?
Explanation:
This is the most common and recommended syntax for defining functional components in modern React, using arrow functions.
What is the primary characteristic of a controlled component in React?
Explanation:
In React, controlled components store their form data within the component's state. Changes to the form input update the state, and the state updates the input's value, making React the single source of truth.
What is the primary role of 'Synthetic Events' in React?
Explanation:
React normalizes events across different browsers using Synthetic Events. This ensures that your event handling code behaves consistently regardless of the user's browser.
What's a common way to bind event handlers in React class components?
Explanation:
Two common approaches to bind event handlers are: 1) using this.handleClick = this.handleClick.bind(this)
in the constructor or 2) using arrow functions directly in the render
method, which lexically scope this
.
How do you pass data from a parent component to a child component in React?
Explanation:
Props are a mechanism in React for passing data down the component tree, from parent to child, enabling communication and data flow between components.