React Hooks Flashcards
useEffect (25 cards)
What is a React hook?
A React hook is a special function that lets you use state and other React features in functional components.
True or False: Hooks can only be used in class components.
False
What hook would you use to manage local state in a functional component?
useState
Fill in the blank: The __________ hook allows you to perform side effects in functional components.
useEffect
What does the useContext hook provide access to?
React context
Multiple choice: Which of the following is NOT a built-in React hook? a) useReducer b) useMemo c) useConnect d) useRef
c) useConnect
How do you define a custom hook?
By creating a function that uses built-in hooks and naming it with ‘use’ prefix.
True or False: Hooks can be called conditionally inside components.
False
What is the purpose of the useMemo hook?
To memoize expensive calculations and avoid recalculating on every render.
What does the useReducer hook help manage?
Complex state logic in functional components.
Fill in the blank: The __________ hook can be used to access the previous state value.
useRef
Multiple choice: Which hook is used to subscribe to context? a) useState b) useContext c) useEffect d) useReducer
b) useContext
What is the return value of the useState hook?
An array with the current state and a function to update it.
True or False: You can use multiple useEffect hooks in a single component.
True
When should you use the useLayoutEffect hook?
When you need to perform synchronous actions after all DOM mutations.
What is the primary difference between useEffect and useLayoutEffect?
useEffect runs after the paint, while useLayoutEffect runs before the paint.
Fill in the blank: The __________ hook is used to persist values between renders without causing a re-render.
useRef
Multiple choice: Which hook is best for optimizing performance by memoizing a value? a) useState b) useMemo c) useEffect d) useCallback
b) useMemo
What does the useCallback hook do?
It returns a memoized version of the callback function that only changes if one of the dependencies has changed.
True or False: Hooks can be called inside loops, conditions, or nested functions.
False
What is the purpose of the useImperativeHandle hook?
To customize the instance value that is exposed when using ref.
Fill in the blank: The __________ hook allows you to share logic between components.
custom hook
How do you handle cleanup in useEffect?
By returning a cleanup function from the effect.
Multiple choice: Which hook would you use to perform an action after a component mounts? a) useEffect b) useMemo c) useReducer d) useState
a) useEffect