Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialiwgpnjvycw
8,577 PointssetState not persisting when page is refreshed
I'm able to add a name to the array, and I can see the array length change in the dev tools, but when I refresh the page, the name I added disappears from the guest array. Has anyone else had this problem?
2 Answers
Matthew Lang
13,483 PointsWhen you refresh your page, you are essentially re-loading your app from scratch. That means, all data you added will be refreshed unless you store it somewhere and load it when your application begins.
khalil et-tkhyly
6,140 Pointsrefreshing the page cause the app to get back to its initial state (your code),however if you're curious about how you can save the state, one solution is to use localStorage, so whenever a change happens to the state you save it to the localstorage and when your app loads grab the stored state in localstorage and assign it to app's state and then your data will be available even when refreshing. hope that helps you
iwgpnjvycw
8,577 Pointsiwgpnjvycw
8,577 PointsOh of course! That was a silly question. Thanks for answering!