Reputation: 785
Currently I'm developing a React web application that needs to store some data from user in the client side and also this data are Important and should not swap suddenly so we can't use Indexed DB.
I just thought about using a file to store data as JSON but in a file that can be stored in user computer and also access to read and write it from React.
Upvotes: 2
Views: 234
Reputation: 109
The best way to work with that is using localStorage. Cookies are mainly for reading server-side, and local storage can only be read by the client-side. Other point is saving data, a big technical difference is the size of data you can store, localStorage give you more space. Check it out https://medium.com/@siobhanpmahoney/local-storage-in-a-react-single-page-application-34ba30fc977d
Upvotes: 2
Reputation: 1680
What you're looking for is the in-browser sessionStorage or localStorage. Having the ability a JSON file to a user's computer would be a major vulnerability and is not possible from a browser/client. I suppose you could create one and trigger a download for them to accept–and then have them subsequently re-upload it when you need the data again. But, I'd argue that session/localStorage is more what you're looking for.
Upvotes: 2