The Call Kent Podcast

Could the useState be used without the setter?


Listen Later

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.

  • useState lazy initialization and function updates
...more
View all episodesView all episodes
Download on the App Store

The Call Kent PodcastBy Kent C. Dodds

  • 5
  • 5
  • 5
  • 5
  • 5

5

2 ratings


More shows like The Call Kent Podcast

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

288 Listeners

Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

Syntax - Tasty Web Development Treats

990 Listeners

PodRocket by LogRocket

PodRocket

61 Listeners