FlashKeepers

Web Development · College · College and University

React II: Hooks

useState, useEffect, useRef, useMemo, useCallback, useContext, useReducer, custom hooks and rules of hooks.

About this set

40 basic cards for College Web Development. Set 2 of 3 in React. It opens with "What does useState return?" and "How do you update state with useState?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does useState return?
Show answerAn array with the state value and a setter function
How do you update state with useState?
Show answerCall the setter function with the new value
When does useEffect run if the dependency array is empty?
Show answerOnly once after the initial render (on mount)
When does useEffect run if you omit the dependency array?
Show answerAfter every render
What is a cleanup function in useEffect?
Show answerA function returned from useEffect that runs before the effect re-runs or on unmount
What does useRef return?
Show answerA mutable object with a .current property
Does updating a ref cause a re-render?
Show answerNo, updating a ref does not trigger a re-render
Name a common use case for useRef
Show answerStoring a reference to a DOM element or accessing it directly
What is the primary purpose of useMemo?
Show answerTo memoize a computed value and avoid recalculating it on every render
When should you use useMemo?
Show answerWhen you have an expensive computation that does not need to run every render
What is the primary purpose of useCallback?
Show answerTo memoize a function definition so it maintains the same reference across renders
Why would you use useCallback?
Show answerTo prevent unnecessary re-renders of child components that depend on the function reference
What does useContext do?
Show answerAllows a component to access context values without prop drilling
What must you do before using useContext?
Show answerCreate a context using React.createContext()
When should you use useReducer instead of useState?
Show answerWhen you have complex state logic or multiple related state updates

25 more cards in the app

Study this set free