if you ask multiple time to update local storage, only the last call is applied. I've done a a codepen to illustrate the issue, with a fix using a ref (thanks to Grok): https://codesandbox.io/p/devbox/serene-monad-7wzycc