Coding task · JavaScript and React course · Module 9: Modern React Hooks
Practice: useMemo for Data Filtering
useMemo(() => calculation, [dependencies]) returns the remembered result and recalculates it only when one of the dependencies changes. The result depends on query and sortBy, not on pings.
Task
App.jsx contains a catalog of eight planets with a search field, a sort list and a "Radio signal" button that changes another state. The filterPlanets function pretends to be an expensive calculation and logs a message to the console every time it runs. Fill in the blanks: ___BLANK1___ is the hook that remembers the result of a calculation between renders, and ___BLANK2___ are the state variables the result depends on (the dependency list). Typing a text and changing the sorting should recalculate the list, clicking "Radio signal" should not. Check in the preview console when the message appears.