-3

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).

Jefter Rocha
  • 387
  • 2
  • 14
  • 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 Answers1

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/

Also this: https://stackoverflow.com/a/53864791/11857649

DPCII
  • 118
  • 1
  • 6