Sveriges mest populära poddar
The Call Kent Podcast

Could the useState be used without the setter?

6 min13 december 2021

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.

Fler avsnitt av The Call Kent Podcast

Visa alla avsnitt av The Call Kent Podcast

The Call Kent Podcast med Kent C. Dodds finns tillgänglig på flera plattformar. Informationen på denna sida kommer från offentliga podd-flöden.