<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/sources/30seconds/best-of/2021/09" -->

---
title: Best 30 seconds of code posts — September 2021 | daily.dev
description: The most upvoted 30 seconds of code posts from September 2021, curated by the daily.dev community.
canonical: https://daily.dev/sources/30seconds/best-of/2021/09
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:url: https://daily.dev/sources/30seconds/best-of/2021/09
og:type: website
og:site_name: daily.dev
og:title: Best 30 seconds of code posts — September 2021 | daily.dev
og:description: The most upvoted 30 seconds of code posts from September 2021, curated by the daily.dev community.
og:image: https://media.daily.dev/image/upload/s--VAY5ToZt--/f_auto/v1724209435/public/daily.dev%20-%20open%20graph
---

# Best of 30 seconds of code — September 2021

1. 1  
[](https://daily.dev/posts/30-seconds-of-code-f9yeujmu0 "30 seconds of code")  
Article  
![Avatar of 30seconds](https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89)30 seconds of code · 5y  
30 seconds of code  
Use the useState() hook with a function toinitial its value lazily. Creates a stateful value that is persisted to sessionStorage. Use a try...catch block and Storage.getItem() to try and get the value. If no value is found, use Storage.setItems() to store the value and use it as the initial state.  
45  
2
2. 2  
[](https://daily.dev/posts/30-seconds-of-code-cdb3ckfhq "30 seconds of code")  
Article  
![Avatar of 30seconds](https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89)30 seconds of code · 5y  
30 seconds of code  
Use the useLayoutEffect() with an empty array as the second argument to execute the provided callback only once when the component is mounted. Use Window.getComputedStyle() to get the overflow value of the body element and store it in a variable. Enables body scroll locking.  
20  
2
3. 3  
[](https://daily.dev/posts/30-seconds-of-code-cm7urzrkz "30 seconds of code")  
Article  
![Avatar of 30seconds](https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89)30 seconds of code · 5y  
30 seconds of code  
Use the useState() hook to create a state variable for the values in the form. Create a function that will be called with an appropriate event by a form field and update the state variable accordingly. Creates a stateful value from the fields in a form.  
16

[See all 30 seconds of code archives](/sources/30seconds/best-of)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@graph":[{"@type":"CollectionPage","@id":"https://daily.dev/sources/30seconds/best-of/2021/09#page","url":"https://daily.dev/sources/30seconds/best-of/2021/09","name":"Best 30 seconds of code Posts — September 2021","description":"The most upvoted 30 seconds of code posts from September 2021, curated by the daily.dev community.","isPartOf":{"@type":"WebSite","url":"https://daily.dev"}},{"@type":"ItemList","@id":"https://daily.dev/sources/30seconds/best-of/2021/09#items","numberOfItems":3,"itemListElement":[{"@type":"ListItem","position":1,"url":"https://daily.dev/posts/30-seconds-of-code-f9yeujmu0","name":"30 seconds of code"},{"@type":"ListItem","position":2,"url":"https://daily.dev/posts/30-seconds-of-code-cdb3ckfhq","name":"30 seconds of code"},{"@type":"ListItem","position":3,"url":"https://daily.dev/posts/30-seconds-of-code-cm7urzrkz","name":"30 seconds of code"}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Sources","item":"https://daily.dev/sources"},{"@type":"ListItem","position":3,"name":"30 seconds of code","item":"https://daily.dev/sources/30seconds"},{"@type":"ListItem","position":4,"name":"Best of","item":"https://daily.dev/sources/30seconds/best-of"},{"@type":"ListItem","position":5,"name":"September 2021"}]}]}
```

