0

Is it ok from a performance point of view to call localStorage.getItem() at render phase? Like this:

function MyComponent() {
  return (
    <Button text={localStorage.getItem('my-key')} />
  );
}
Syener
  • 5
  • 2
  • You should not if the localstorage item changes your component wont rerender automatically – adsy Jan 28 '23 at 04:57
  • @yqlim Looks like performance is pretty low comparing to usual ES objects. I can infer that it's better no to use localStorage.getItem at render phase. Thank you. – Syener Jan 28 '23 at 12:16

0 Answers0