We have several places in our React components where we import and use lodash's throttle directly, but because of React's component lifecycle, a new throttle function would be created on every component render, meaning it won't actually throttle if a re-render is triggered.
But we should add that useThrottle hook back (see: e7557b6f52774c458cfdd87a92256c020f70fcbc for its commit) and migrate existing throttle calls to use a safer, re-render-persistent throttle function created from a React hook.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Feature Description
We have several places in our React components where we import and use lodash's
throttle
directly, but because of React's component lifecycle, a newthrottle
function would be created on every component render, meaning it won't actually throttle if a re-render is triggered.@nfmohit noticed this when working on #7045. He even helpfully created a
useThrottle
hook, but then it turns out we didn't need it for that particular PR (see: https://github.com/google/site-kit-wp/pull/7122#discussion_r1213757173).But we should add that
useThrottle
hook back (see: e7557b6f52774c458cfdd87a92256c020f70fcbc for its commit) and migrate existingthrottle
calls to use a safer, re-render-persistent throttle function created from a React hook.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
Test Coverage
QA Brief
Changelog entry