Component Definition
Which of the following is the correct way to define a functional component in React?
- A) function MyComponent = () =u003E { return u003Cdivu003EHellou003C/divu003E; }
- B) const MyComponent = { return u003Cdivu003EHellou003C/divu003E; }
- C) const MyComponent = function() { return u003Cdivu003EHellou003C/divu003E; }
- D) class MyComponent extends React.Component { render() { return u003Cdivu003EHellou003C/divu003E; } }
- E) const MyComponent = () =u003E { return u003Cdivu003EHellou003C/divu003E; }
Props Usage
How do you pass data from a parent component to a child component in React?
- A) Using the 'transfer' attribute.
- B) Using 'state' directly.
- C) Using 'props'.
- D) Using 'context' globally.
- E) Using 'inject' method.
State Management
Which hook is used to manage state within a functional component?
- A) useReducer()
- B) useContext()
- C) useState()
- D) useMemo()
- E) useEffect()
Event Handling Syntax
In React, how do you bind an event handler to an element?
- A) u003Cbutton onclick={this.handleClick()}u003EClick Meu003C/buttonu003E
- B) u003Cbutton on-click={this.handleClick()}u003EClick Meu003C/buttonu003E
- C) u003Cbutton event='onClick' handler={this.handleClick}u003EClick Meu003C/buttonu003E
- D) u003Cbutton onClick={this.handleClick}u003EClick Meu003C/buttonu003E
- E) u003Cbutton onAction={this.handleClick()}u003EClick Meu003C/buttonu003E
useEffect Dependency Array
What is the purpose of the dependency array in the useEffect hook?
- A) To specify the initial state.
- B) To determine which props should be updated.
- C) To indicate which values, when changed, should trigger the effect.
- D) To define the cleanup function.
- E) To optimize the effect's re-rendering frequency.
Component Re-rendering
What can cause a React component to re-render?
- A) Only when the parent component re-renders.
- B) Only when the 'forceUpdate' function is called.
- C) Changes to its props, state, or when its parent re-renders.
- D) When a global variable changes.
- E) Only on initial mount.
Custom Hooks
What is the primary benefit of using custom hooks in React?
- A) They automatically optimize performance.
- B) They allow you to write CSS directly within your components.
- C) They enable reusable stateful logic between components.
- D) They replace class components entirely.
- E) They provide direct access to the DOM.
State Immutability
Why is it important to update state immutably in React?
- A) It prevents memory leaks.
- B) It makes the code shorter.
- C) It allows React to efficiently detect changes and optimize re-renders.
- D) It automatically handles event binding.
- E) It's required for Server Side Rendering.
Event Handling Scope
In a class component, how do you ensure that 'this' is correctly bound within an event handler?
- A) Always use arrow functions for event handlers directly in the JSX.
- B) Use the 'bind' method in the constructor or use arrow functions as class properties.
- C) Use the 'apply' method within the render function.
- D) It's not necessary; 'this' is always correctly bound.
- E) Define all event handlers as global functions.
Performance Optimization
Which hook can be used to memoize the result of a computationally expensive function?
- A) useReducer
- B) useCallback
- C) useState
- D) useMemo
- E) useContext