You cannot access the file system from a browser for security reasons. If you just want to access it after it is refreshing, I think you can save it in LocalStorage when the state changes, and then use it when the component is loaded, if it is not undefined (you can check this in componentDidMount ) (The code below is not tested)
addEmployee(employee) { let newEmployees = this.state.employees.concat([employee]) localStorage.setItem('employees', JSON.stringify(newEmployees)); this.setState({ employees: newEmployees }); } componentDidMount(){ let newEmployees = localStorage.employees if(newEmployees != undefined){ this.setState({ employees: JSON.parse(newEmployees) }); } }
If you want to keep this JSON persistently, and you want more than being able to use it after the upgrade, you have to do it on the backend. You can also allow the user to save the file manually (with a download prompt), as described here .
source share