#help with localStorage
1 messages · Page 1 of 1 (latest)
Could you post a link to a live version of your project on Netlify or GitHub instead? Can't really answer a question without seeing the code, and it's much easier to answer if one can just directly manipulate it. It's easier to do that in the Scrimba editor, but it can also be done in dev tools as a second-best alternative...
My code is not working on scrimba
Can I just send you the zipped version?
@potent lion Here is the link: https://scrimba.com/scrim/co335495f9ab6f0dc442fb286?a=37019.0.3.L228_2. I removed the part with the onload function. My idea was to check if something is saved in localStorage and if so render that out. I tried to save the content of main and also the data array itself but every time strange things happened. By that I mean that all likes disappeared if I clicked something else or I wasn't able to like or retweet anymore. I also feel like my code is not very clean. Maybe you can help me out.
You don't need to use onLoad to do what you're trying to do with checking if there's something already saved in localStorage. You can just set up a function that gets invoked in your main JS file and have it follow logic like this:
-
check if the data is already in local storage.
-
If so, load that as the data to use for rendering.
-
If not, use the pre-built data by default.
As for what's going wrong when you try to save things, I have no idea without seeing what you've tried. Except for the commented out code on line 6, I don't see anything related to local storage in what you've shared above
I deleted it because it wasn't working
Alright, but I can't tell you why it's not working if I can't see it!
One moment
Alright, I gotta take my dog out. I'll be back in a bit
Is there a way to make the imported array changeable? I think it's read-only
Alright, I will post the new version here
@potent lion
Now I am in the weird situation again: https://scrimba.com/scrim/co335495f9ab6f0dc442fb286?a=37934.0.3.L20_3
I can load the saved data but then no user interaction is possible anymore.
It seems to be working fine to me? Have you changed something?
Ah, I see what you mean
So if I click a heart, it will save the heart, and then I can undo the heart (or load it from local storage), but then I can't type in the input anymore
Yeah, basically all user interactions like replying and liking aren’t working after reloading
I actually have no idea how to solve this
I think there are going to be more bugs to sort out after this, but one thing that is standing out to me is that you're still using tweetsData in a lot of functions, as opposed to arrayToUse — which means that you're going to end up loading the local storage array initially, but then it's going to be saving changes to the original array instead of the new array. I'm not sure how much mileage you'll get out of changing that, but maybe try starting there?
I will, but I think there will be much more. I appreciate your help.
Let me know. I'll be back later