memo, useMemo and useCallback — Concept Check
Questions on memo, useMemo and useCallback. Memoisation trades memory and complexity for skipped work. Applied without measuring, it usually makes code slower to read and no faster to run.
Questions in this quiz
7 questions on memo, useMemo and useCallback — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have a component that filters and sorts 10,000+ rows. Which optimization should you consider?
- AUse useMemo to cache the filtered and sorted rows
- BUse useCallback to cache the filtering function
- CUse memo to skip re-rendering the component
- DNo optimization is needed for this scenario
2.A component re-renders every time a parent component's state changes. What could be a solution?
- AUse useCallback for all functions in the component
- BUse useMemo for all values in the component
- CUse memo on the child component with stable props
- DUse useMemo to cache the component
3.What happens if you use memo on a component but pass new function props each render?
- AThe component will not render at all
- BuseCallback should be used instead
- Cmemo will not skip re-rendering
- Dmemo will skip re-rendering as expected
4.Why might useMemo be unnecessary in a component rendering a list of 50 items?
- AThe list is too small for useMemo to have a measurable impact
- BuseMemo is only for caching functions
- CReact automatically caches small lists
- DuseMemo should be used for all lists
5.A component uses a function as a dependency in useEffect. What's a potential issue?
- AuseMemo should be used instead
- BuseCallback should be used for all functions
- CuseEffect doesn't work with functions
- DThe function identity changes, causing re-runs
6.When is it justified to use useCallback in a React component?
- ATo avoid any re-renders
- BWhen a function is used more than once
- CWhen passing functions to memoized children
- DFor all functions in a component
7.How can React DevTools Profiler help in optimizing a component?
- ABy preventing re-renders
- BBy identifying components with long render times
- CBy automatically applying memoization
- DBy suggesting which hooks to use