In a recent debugging session on a client project, we found that some unnecessary state changes were being kicked off by the use-page-errors hook, specifically the resetPageErrors function that is exported. Add a simple check with the callback version of setPageErrors to check to see if the previous state has values - if it doesn't, there's no need to set the state and cause a re-render to consuming components (due to referential inequality of arrays).
In a recent debugging session on a client project, we found that some unnecessary state changes were being kicked off by the
use-page-errors
hook, specifically theresetPageErrors
function that is exported. Add a simple check with the callback version ofsetPageErrors
to check to see if the previous state has values - if it doesn't, there's no need to set the state and cause a re-render to consuming components (due to referential inequality of arrays).Before:
After: