I use redux for state management. Now I have a json object of 1000 objects that I need to store locally either in asyncStorage or in a state to use it in different part of my application. What is the best way to handle this json data
const initialState = {
loading: false,
dataAppDB:{}
}
try {
await fetch(url)
.then(response => response.json())
.then(data => {
thunkAPI.dispatch(saveDataApp(data));
let data1 = JSON.stringify(data);
AsyncStorage.setItem('dataAppDB', data1);
});
} catch (e) {
}
}
}
Is it normal to store these 1000 json objects in for example in state : dataAppDB = {} and to be able to use it in my application
CodePudding user response:
That will depend on one simple question. Do you need the data to persist after the app was closed?
If yes, then using AsyncStorage is a valid approach. Of course, you can also have a proper backend with a database, but AsyncStorage will do the job.
If not, then what you want is to use a context, for this you have different options. A common one is the hook useContext, but redux is also a very good alternative.