Hello @kartik,
The best way to save data when you want to repopulate it at a later point of time is to save it in localStorage, which allows you to get the data even after refreshing the app
const InitialState = {
someState: 'a'
}
class App extends Component {
constructor(props) {
super(props);
// Retrieve the last state
this.state = localStorage.getItem("appState") ? JSON.parse(localStorage.getItem("appState")) : InitialState;
}
componentWillUnmount() {
// Remember state for the next mount
localStorage.setItem('appState', JSON.stringify(this.state));
}
render() {
...
}
}
export default App;
Hope it works!!
To know more about React, We highly recommend to join React.js Training Course today.
Thank You!!