Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

expo - Undefined is not an object (evaluating 'RCTAsyncStorage.multiMerge' (React-native-asyncstorage)

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: enter image description here

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);
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...