I am developing a solution to a challenge proposed to me by a company. The chanllenge is develop a ReactJS app and its required to store some datas in a JSON file, but in no time its required to build some service or API, just a ReactJS app and as far as I know its not possible handle files in client-side(write).
Asked
Active
Viewed 38 times
-3
-
Sure you can :) Just don't think about writing the file directly -- that's not possible client-side -- but you can definitely trigger a download of a generated file :) – IceMetalPunk Jan 15 '20 at 21:15
1 Answers
0
To set:
let jsonObj = {"name": "Bob", "age": 100}
localStorage.setItem('userList', JSON.stringify(jsonObj))
To retrieve:
console.log(JSON.parse(localStorage.getItem('userList')))
// {name: "Bob", age: 100}
You can also try this link for implementing with React: https://programmingwithmosh.com/react/localstorage-react/

DPCII
- 118
- 1
- 6