未定义不是对象(评估 'RCTAsyncStorage.multiMerge' (React-native-asyncstorage) [英] Undefined is not an object (evaluating 'RCTAsyncStorage.multiMerge' (React-native-asyncstorage)

查看:15
本文介绍了未定义不是对象(评估 'RCTAsyncStorage.multiMerge' (React-native-asyncstorage)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处遇到了与 react-native-asyncstorage 相关的问题:

我使用的是 react-native 0.52.0,这个问题可能是由于 react-native-asyncstorage 的依赖造成的:

<块引用>

react-native-asyncstorage@1.0.0 需要一个react-native@^0.47.2 但没有安装.您必须安装对等自己依赖.

奇怪的是它适用于 Android,但不适用于 iOS 和 iOS 模拟器.

有人可以帮忙吗?

编辑

我想补充一些可能有用的点:

  • 我使用 Expo 进行开发,
  • 我已经在我的代码中注释了每个 AsyncStorage,但问题仍然存在,
  • 按照评论中的要求,这是我的 AsyncStorage 代码的截断代码

-

import { AsyncStorage } from 'react-native';导出异步函数 SetItem(strKey, objValue) {尝试 {if (typeof(objValue) === 'string') {等待 AsyncStorage.setItem(strKey, objValue);}别的 {等待 AsyncStorage.setItem(strKey, JSON.stringify(objValue));}}捕捉(错误){控制台日志(错误);}}

解决方案

正如文档中所说:注意:并非所有本机实现都支持此功能,您可能会在错误中运行,因为这个.

也可能是您正在使用的 Reactotron(根据堆栈跟踪)导致此问题.首先尝试禁用它?

您是否有 AsyncStorage 的自定义实现(例如:https://www.npmjs.com/package/react-native-asyncstorage)?如果是这样,除非有特定原因使用它,否则请取下它(请在问题中详细说明)

但总的来说,您可以使用 React Native Simple Store 它是 update 方法.

然后您可以使用 lodash.merge 编写自己的函数.p>

如果即使注释掉所有 AsyncStorage 代码、删除可能的自定义依赖项并取消 Reactotron,问题仍然存在,并且您找不到自己编写 multiMerge 的方法,请更新您的问题并在此答案上联系我.

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);
    }
}

解决方案

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.

这篇关于未定义不是对象(评估 'RCTAsyncStorage.multiMerge' (React-native-asyncstorage)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆