EPISODE · Dec 13, 2021 · 6 MIN
Could the useState be used without the setter?
from The Call Kent Podcast · host Kent C. Dodds
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 sessionStorageconst [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.useState lazy initialization and function updates
Embed this episode
NOW PLAYING
Could the useState be used without the setter?
No transcript for this episode yet
Similar Episodes
No similar episodes found.
Similar Podcasts
No similar podcasts found.