
Season 2 ยท Episode 2
Could the useState be used without the setter?
Claudia asked this on 2021-11-29
December 13, 20216m 3s
Audio is streamed directly from the publisher (media.transistor.fm) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.
Show Notes
I have a question... could the useState be used without using the setter? because a teammate use it in that way to get an item from sessionStorage
const [initialScrollPosition] = useState(() => Number.parseFloat(sessionStorage.getItem('offset') || 0));and argues that this is so that the component is not unnecessarily rerendered and to read the sessionStorage only once! ๐ค but I think we can use useMemo for those cases but the useState is still used in this form in several components.
Topics
reactuseStatelazy initialization