Illustration of a microphone

Calls with Kent C. Dodds.

You call, I'll answer.

Listen to the podcasts here
Phone sitting on a stool

What's this all about?

The goal of the Call Kent Podcast is to get my answers to your questions. You record your brief question (120 seconds or less) right from your browser. Then I listen to it later and give my response, and through the magic of technology (ffmpeg), our question and answer are stitched together and published to the podcast feed.

I look forward to hearing from you!

Record your call

Calls with Kent C. Dodds — 60 episodes

52.Could the useState be used without the setter?
06:03
Keywords

react, useState, lazy

Tweet this
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.

Looking for more content?

Have a look at these articles.

See the full blog