0
0
React Nativemobile~5 mins

useEffect hook in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARuns the effect only when the component unmounts
BRuns the effect after every render
CPrevents the effect from running at all
DRuns the effect only once after the first render
Where should you put cleanup code for subscriptions or timers in useEffect?
AInside the main body of the effect
BOutside the component
CIn a function returned from the effect
DIn the dependency array
What happens if you omit the dependency array in useEffect?
AEffect runs after every render
BEffect runs only once
CEffect never runs
DEffect runs only on unmount
Which of these is NOT a typical use case for useEffect?
ADefining a component's state
BSetting up a timer
CSetting up event listeners
DFetching data from an API
If you want an effect to run when a specific variable changes, where do you list that variable?
AInside the effect function
BIn the dependency array
CIn the cleanup function
DIn the component's props
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.