问题
I am having an issue related to react-native-asyncstorage from here: https://facebook.github.io/react-native/docs/asyncstorage.html
When I run react-native run-ios
, the following error appears:
I am using react-native 0.52.0 and this problem may be due to the dependency of react-native-asyncstorage:
react-native-asyncstorage@1.0.0 requires a peer of react-native@^0.47.2 but none is installed. You must install peer dependencies yourself.
The odd thing is it works fine for Android, but not for both iOS nor iOS emulator.
Can someone help?
EDIT
I would like to add some points that maybe useful:
- I use Expo for development,
- I have commented every AsyncStorage in my code, but the problem still persist,
- As asked in the comment, here is the snipped code of my AsyncStorage code
-
import { AsyncStorage } from 'react-native';
export async function SetItem(strKey, objValue) {
try {
if (typeof(objValue) === 'string') {
await AsyncStorage.setItem(strKey, objValue);
}
else {
await AsyncStorage.setItem(strKey, JSON.stringify(objValue));
}
}
catch(error){
console.log(error);
}
}
回答1:
Like said in the documentation: NOTE: This is not supported by all native implementations, you're probably running in an error because of this.
It may also be Reactotron you're using (according to the stack trace) that causes this. Try disabling it at first?
Are you having a custom implementation of AsyncStorage
(like: https://www.npmjs.com/package/react-native-asyncstorage)? If so, take it off unless there's a specific reason to use it (please elaborate in the question)
But in general, you could for instance use React Native Simple Store and it's update
method.
Or then you could write your own function with lodash.merge.
If problem persists even with commenting out all the AsyncStorage code, removing possible custom dependencies and taking off Reactotron, and you can't find a way to write multiMerge by yourself, update your question and ping me on this answer.
来源:https://stackoverflow.com/questions/50075823/undefined-is-not-an-object-evaluating-rctasyncstorage-multimerge-react-nativ