Could the useState be used without the setter? - podcast episode cover

Could the useState be used without the setter?

Dec 13, 20216 minSeason 2Ep. 2
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

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.

For the best experience, listen in Metacast app for iOS or Android