Recall & Review
beginner
What is the purpose of the
useEffect hook in React Native?The
useEffect hook lets you run code after the component renders. It helps manage side effects like fetching data, setting up subscriptions.Click to reveal answer
beginner
How do you run an effect only once when a component mounts using
useEffect?Pass an empty array
[] as the second argument to useEffect. This tells React to run the effect only once after the first render.Click to reveal answer
intermediate
What happens if you omit the dependency array in
useEffect?The effect runs after every render, which can cause performance issues or unwanted repeated actions.
Click to reveal answer
intermediate
How can you clean up side effects in
useEffect?Return a cleanup function inside
useEffect. This function runs before the effect runs again or when the component unmounts, useful for removing subscriptions or timers.Click to reveal answer
intermediate
Explain the role of the dependency array in
useEffect.The dependency array tells React when to re-run the effect. The effect runs only if one of the dependencies changes between renders.
Click to reveal answer
What does passing an empty array
[] as the second argument to useEffect do?✗ Incorrect
An empty dependency array means the effect runs once after the component mounts.
Where should you put cleanup code for subscriptions or timers in
useEffect?✗ Incorrect
Returning a function from
useEffect lets React clean up before re-running or unmounting.What happens if you omit the dependency array in
useEffect?✗ Incorrect
Without dependencies, the effect runs after every render.
Which of these is NOT a typical use case for
useEffect?✗ Incorrect
State is defined with
useState, not useEffect.If you want an effect to run when a specific variable changes, where do you list that variable?
✗ Incorrect
Variables that trigger the effect to re-run go in the dependency array.
Describe how the
useEffect hook works and why it is useful in React Native.Think about when and why you need to do things like fetch data or set timers.
You got /4 concepts.
Explain the importance of the dependency array in
useEffect and what happens if it is empty or missing.Consider how React Native decides when to run your effect.
You got /4 concepts.