What is a key feature of custom hooks in React? - They allow you to manipulate the…
- User
What is a key feature of custom hooks in React?
-
They allow you to manipulate the Document Object Model directly within your functional components.
-
They provide a way to use lifecycle methods within class components.
-
They are an advanced feature of React that allow you to break component logic into smaller reusable functions.
-
They speed up render times by reducing the amount of code that React needs to evaluate.
-
- Assistant
A key feature of custom hooks in React is:
- They are an advanced feature of React that allow you to break component logic into smaller reusable functions.
- User
Which of the following statements about the useState hook are correct?
useState returns an array with two elements: the current state value and a function to update it.
useState can accept a function as an argument.
useState triggers re-rendering of a component whenever the state changes.
useState can only be used inside the render method of a class component.
- Assistant
The correct statements about the useState hook are:
-
useState returns an array with two elements: the current state value and a function to update it.
-
useState triggers re-rendering of a component whenever the state changes.
Additionally, useState can accept a function as the initial state if you need to compute the initial state lazily, but not just any function as an argument. The incorrect statement is:
- useState can only be used inside the render method of a class component. (This is incorrect because useState can only be used inside functional components, and not class components).
-