[英]Local Storage not saving everything
I'm trying to use the local storage to save a specific state in redux so that the client would not have to make the axios calls every time to fill up the database. 我正在尝试使用本地存储在redux中保存特定状态,以使客户端不必每次都进行axios调用来填充数据库。 However, only 71% of the given database seems to be saving in the local storage every time, and I wasn't sure why this was happening.
但是,每次给定数据库的71%似乎每次都保存在本地存储中,我不确定为什么会这样。
This is my local storage code (using the one in Dan's tutorial). 这是我的本地存储代码(使用Dan的教程中的代码)。
export const loadState = () => {
try {
const serializedState = localStorage.getItem('state');
if(serializedState === null){
return undefined
}
return JSON.parse(serializedState);
} catch (err){
return undefined;
}
};
export const saveState = (state) => {
try {
const serializedState = JSON.stringify(state);
localStorage.setItem('state', serializedState);
} catch(err){
///
}
};
Setting up the store 开设商店
const persistedState = loadState();
const createStoreWithMiddleware = applyMiddleware(promise)(createStore);
const store = createStoreWithMiddleware(reducers, persistedState);
store.subscribe(()=>{
saveState({
pokemons: store.getState().pokemons
});
});
The component is supposed to look for the current pokemon array's length to determine whether it needs to make more axios calls. 该组件应该寻找当前口袋妖怪阵列的长度,以确定是否需要进行更多的axios调用。
componentDidMount(){
let promises = [];
for(var i = this.props.pokemons.length; i < 10; i++){
promises.push(this.props.fetchPokemons(i));
}
axios.all(promises).then(()=>{
this.props.mapPokemons(this.props.pokemons);
this.setState({
loading: false
})
})
}
Every time the page is refreshed, the this.props.pokemons only seems to be holding 71% of the data. 每次刷新页面时,this.props.pokemons似乎仅保留71%的数据。 Even when I clear the local storage and try to fill up the redux state again, only 71% of the data is there when I refresh the page.
即使清除本地存储并尝试再次填充redux状态,刷新页面时也只有71%的数据在那里。
Any help would be appreciated, 任何帮助,将不胜感激,
Thank you 谢谢
可能您正在尝试存储的数据超过本地存储可用的最大内存(例如,对于Google Chrome浏览器为5MB) 。
What is the size of the data that you want to put in the sotrage ? 您要放入存储中的数据大小是多少? Because if the size is bigger than 5MB, only 5MB will be stored
因为如果大小大于5MB,将仅存储5MB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.