What does the dependencies array in useEffect control?

Master ReactJS with our comprehensive test. Practice with multiple-choice questions and detailed explanations. Build your skills for the exam with our engaging format and expert tips!

Multiple Choice

What does the dependencies array in useEffect control?

Explanation:
The dependencies array controls when the effect re-runs. React watches the values you put in that array and re-executes the effect only if any of them changed since the last render. If you provide an empty array, the effect runs once after the initial render. If you omit the array altogether, the effect runs after every render. The other behavior you might be thinking of—cleanup when unmounting or before the next run, or touching specific DOM elements—is handled by the code inside the effect itself, not by the dependencies list.

The dependencies array controls when the effect re-runs. React watches the values you put in that array and re-executes the effect only if any of them changed since the last render. If you provide an empty array, the effect runs once after the initial render. If you omit the array altogether, the effect runs after every render. The other behavior you might be thinking of—cleanup when unmounting or before the next run, or touching specific DOM elements—is handled by the code inside the effect itself, not by the dependencies list.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy