Create a custom useLocalStorage React hook

preview_player
Показать описание
Let's just make a quick little useLocalStorage hook

(note, hooks are not stable, but by the time they are, every hook conceivable will have been written and open sourced already... I'm pretty sure there are at least 10 localstorage hooks on npm already).
Рекомендации по теме
Комментарии
Автор

Kent is really "the" React teacher you need. His courses on egghead.io are worth every second you spent on them.

frfancha
Автор

Thank you Kent, it was sooo helpful :) How simple you explained it!

Rose-
Автор

You're my new favorite coding channel! I'm in love.

swssdev
Автор

Awesome video :)
Quick reference timestamps:
- Simplest logic for useState for an onClick counter: 3:04
- Base logic for localStorage to increment a persistent number on click is complete: 6:04 (no new functions yet)
- Explanation for why Kent chooses to use useEffect instead of an extra function to clear count: 7:19
- Starting to build the useLocalStorage custom hook: 8:16
- Using the newly created useLocalStorage custom hook: 10:31
- Showing a third party NPM library that provides many custom hooks, including useLocalStorage: 12:31

berrywarmer
Автор

Met ya last week and been watching your videos on hooks 👍

mlala
Автор

Hooks are very, very cool guys. Please enjoy them.

khgriffi
Автор

hey kent. awesome video. had a quick question about useState and localStorage - could you just write || 0) instead of using the function? whats the benefit of returning a function that returns the value rather than just the value?

yangyu
Автор

Could someone explain why he's getting that error in 5:27? That should simply return 0 if nothing's found in LS

Shakas
Автор

Why the codesandbox link is not given in the description, so that we can copy and paste and get into ti? :)

aruprakshit
Автор

Great video Kent !
Do you think using localStorage (sync) in Js app is a good solution ?

williamsyeo
join shbcf.ru