Save State to LocalStorage & Persist on Refresh with React.js

Save State to LocalStorage & Persist on Refresh with React.js

Colby Fayock

2 года назад

92,794 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Johanes Alberto
Johanes Alberto - 16.09.2023 11:48

thank you so much brother

Ответить
Rhazeb Brown
Rhazeb Brown - 14.09.2023 17:25

hi colbyfaycock, please can you do a video where when you logout from the redux it saves everything done so when you log back in it is persisted base on the user that logs in.

Ответить
Prateek Suman
Prateek Suman - 13.08.2023 15:32

Thank you so much!!

Ответить
Joe Du
Joe Du - 21.07.2023 18:56

Great video, thanks. for the Token what should we do about it to make it safe?

Ответить
Joe Du
Joe Du - 21.07.2023 18:55

Can I read the localstorage value first, if the local storage value exists, I will use this value as a flag to decide show the banner or not, if the local storage value is null or undefined, I will set the flag to true.( the first time render the page), in this case the banner won't flash after you hided and refresh the page.

Ответить
Vlad Raileanu
Vlad Raileanu - 20.06.2023 20:51

Great stuff man, damn those cookies, this approach is much simpler for what i needed, thank you! :x

Ответить
Misael Castillo
Misael Castillo - 23.05.2023 22:44

Thank you!

Ответить
Electric Sober Goose
Electric Sober Goose - 20.05.2023 09:30

Hey, I'm building an application in which the data is obtained from the local storage, but as to display them, I always need to refresh the page. I want them to display right away. I tried useEffect with a value in the dependency array, but it causes too many re-renders. Is there any way to update state without refreshing?

Ответить
Nathan Reed
Nathan Reed - 28.04.2023 20:59

I was having issues with the local storage being written to my default sate on every refresh. I ended up getting it fixed by adding an arrow function to my useState that returns the local storage value if it’s defined or the default if not.

Ответить
daki sunshine
daki sunshine - 20.04.2023 14:40

Hello Colby, the tutorial was great! I was followig along but my local storage is, sadly, refreshing all the time. No error nothing, dont you know what it can be? Im using object aj state instead. Thanks!

Ответить
Radu Padurariu
Radu Padurariu - 12.04.2023 16:53

how would you replace useEffect with componentDidMount on class component? I need to use localStorage on a class component.

Ответить
Koa Garces
Koa Garces - 11.04.2023 01:20

Honestly, this guy is great at teaching. Keep it up man!

Ответить
Piyush Nextupgrad
Piyush Nextupgrad - 10.04.2023 16:54

i am making a todo list for practice and doing everything correct still local storage gets cleared on refresh any help?

Ответить
Jamie Tse
Jamie Tse - 06.04.2023 03:51

i m not an english native speaker. i pause and rewatch your steps couple of times to figure out what you have done. :) and i totally get it!!😁you explain very well!! thumb's up for you thank you!

Ответить
annu
annu - 20.03.2023 12:31

Can anyone pls tell me why my Value is shown as [object Object] ? I have followed this video carefully and used it for saving the theme which was pre selected. Also, my useState looks like
const [theme, setTheme] = useState('classicTheme');

where classicTheme and 4 more themes are defined in my themes.jsx file. The themes can be changed using a switch case.

Also, removed strict mode from index.js :(

Ответить
Tigge Nilsson
Tigge Nilsson - 03.03.2023 16:43

Amazing! Thanks a lot.

Ответить
Prince Ajayi
Prince Ajayi - 01.03.2023 15:46

Thank you very much for the video
Pls is there a way to avoid the short time flash from showing
I have a NextJS app where a user can change the primary colour used on the page. I had to store the colour the user picked last in the browser's session storage
But there's this short time flash of the default colour when the user refreshes the page before it gets updated by react state
So is there a way to avoid the flash🙏

Ответить
Oreki
Oreki - 27.02.2023 21:27

You're so good at teaching man.. 🙏🙏

Ответить
Tom Ainsworth
Tom Ainsworth - 26.02.2023 23:20

Great vid Colby. This is really helpful and exactly what I wanted to know, thank you!

Ответить
Yubin Jo
Yubin Jo - 21.02.2023 18:05

thank you for such a good explanation

Ответить
Sean Coutinho
Sean Coutinho - 18.02.2023 02:36

Loved this tutorial a lot

Ответить
The Loner Coder
The Loner Coder - 13.02.2023 23:03

man this was beautifully explained. Wish I found this channel when I was first learning React.

Ответить
Douha Hasoon
Douha Hasoon - 29.01.2023 11:04

greater tutorial! thank you.

Ответить
Izhar Jumadi
Izhar Jumadi - 24.01.2023 15:04

Thanks for the short and concise explanation!

Ответить
Petros Pollakis
Petros Pollakis - 22.01.2023 19:48

Amazing video. Keep going bro!

Ответить
sadmeowmeow
sadmeowmeow - 15.01.2023 16:43

wow your teaching is so straight forward, just directly hits into brain.

Ответить
netsaosa
netsaosa - 11.01.2023 09:54

space jelly

Ответить
Yara Zarin
Yara Zarin - 09.01.2023 08:45

Thank you so much!💝💝

Ответить
hunterbidenafterlife
hunterbidenafterlife - 04.01.2023 14:09

Thanks, could someone explain why

if(data !== null){
setShowBanner(JSON.parse(data))
}

works but

if(data){
setShowBanner(JSON.parse(data))
}

does not work.

Ive been ripping my hair out for hours

Ответить
Nitish Vobilisetti
Nitish Vobilisetti - 01.01.2023 10:20

How do we persist it if we change pages to a different link?

Ответить
Alexandros Kyriakou
Alexandros Kyriakou - 25.12.2022 19:09

amazing tutorial experience! looking forward for more <3

Ответить
Agata Duda
Agata Duda - 13.12.2022 18:14

Great Video! Thanks a mill

Ответить
Aliton Oliveira
Aliton Oliveira - 11.12.2022 00:26

Hello, Colby! How to get rid of the banner flash just after the page refresh?

Ответить
Bernardo de Souza Silva
Bernardo de Souza Silva - 06.12.2022 16:15

Thank you, amazing video!

Ответить
yuan quan
yuan quan - 04.12.2022 15:22

Now with strict mode... it's broken.... kinda...

Ответить
Melissa Vela
Melissa Vela - 28.11.2022 06:54

what a good explanation!! Thanks a lot

Ответить
Devin Outfleet
Devin Outfleet - 17.11.2022 05:39

Colby! You are such an AMAZING teacher! You have a gift my brother wow. Keep it up man you will reach and help so many people regardless of the industry you are in, I just know it. Keep going, you are truly gifted.

Ответить
MrBeard
MrBeard - 10.11.2022 18:36

this helped me thanks dude

Ответить
Eric Rosén
Eric Rosén - 06.11.2022 16:13

Amazing, many thanks for a great tutorial. It's super helpful that you describe as much as you do around the topic.

Ответить
TechLight
TechLight - 30.10.2022 13:47

Great video and thank you for knowledge.

Ответить
ryan brilliant
ryan brilliant - 16.10.2022 02:12

amazing, so calm, and simple

Ответить
Gabriel Martínez
Gabriel Martínez - 11.10.2022 23:48

Hey Colby. Can you perhaps share a hook snippet for local storage? Every thing I find doesn't take into consideration SSR.

Ответить
usmonzo
usmonzo - 07.10.2022 17:38

idk why but its not working in my project(

Ответить
Human Touch Art
Human Touch Art - 05.10.2022 01:44

ok i think i found a solution for some reason strict mode in next.js config file was preventing me to store local storage on update .... just change next.js config module.exports = {
reactStrictMode: false,
} and it should work

Ответить
dr_morpho
dr_morpho - 29.09.2022 19:40

Thank you ) 🤝

Ответить
Oluwatimilehin Eribake
Oluwatimilehin Eribake - 27.09.2022 23:25

I don't think I have enjoyed a tutorial video this much, it was so calm and I understood every bit of it, big ups!

Ответить
Carlos Pavajeau
Carlos Pavajeau - 25.09.2022 00:17

GG ! finally something that works ahahah

Ответить
sudeep shetty
sudeep shetty - 20.09.2022 10:15

hey, i cant able to store the data, when i refresh page it is showing true, could you help me

Ответить