HarmonyOS 鸿蒙Next中RN使用AsyncStorage报错
HarmonyOS 鸿蒙Next中RN使用AsyncStorage报错 我使用metro调试开发,出现了报错,该怎么排查啊?
TypeError: _RCTAsyncStorage.default.multiGet is not a function (it is undefined)
TypeError: _RCTAsyncStorage.default.multiGet is not a function (it is undefined)
at anonymous (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:126407:44)
at tryCallTwo (/Users/admin/Desktop/rnoh/publish/build_release/arm64-v8a-output/lib/InternalBytecode/InternalBytecode.js:61:9)
at doResolve (/Users/admin/Desktop/rnoh/publish/build_release/arm64-v8a-output/lib/InternalBytecode/InternalBytecode.js:216:25)
at Promise (/Users/admin/Desktop/rnoh/publish/build_release/arm64-v8a-output/lib/InternalBytecode/InternalBytecode.js:82:14)
at getItem (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:126405:27)
at getItem (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:125799:58)
at Storage (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:125792:38)
at anonymous (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:124993:48)
at loadModuleImplementation (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:328:14)
at guardedLoadModule (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:227:38)
at metroRequire (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:123:92)
at anonymous (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:122961:113)
at loadModuleImplementation (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:328:14)
at guardedLoadModule (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:227:38)
at metroRequire (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:123:92)
at anonymous (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:122894:109)
at loadModuleImplementation (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:328:14)
at guardedLoadModule (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:227:38)
at metroRequire (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:123:92)
at anonymous (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:1465:104)
at loadModuleImplementation (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:328:14)
at guardedLoadModule (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:219:47)
at metroRequire (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:123:92)
at global (http://localhost:8081/index.bundle//&platform=harmony&dev=true&minify=false:261681:4)
更多关于HarmonyOS 鸿蒙Next中RN使用AsyncStorage报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3 回复
这边没有复现你的问题,你可以参考文档中的步骤进行开发, https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-async-storage-async-storage.md
参考demo
import React,{useState} from 'react';
import AsyncStorage from "@react-native-async-storage/async-storage";
import { View,Text,Button } from "react-native-harmony";
// Storing data
export function AsyncDemo(): JSX.Element{
const [storageValue,setStorageValue] = useState("张三")
const storeData = async () => {
try {
await AsyncStorage.setItem("my-key", "李四");
} catch (e) {
}
};
// Reading data
const getData = async () => {
try {
const value = await AsyncStorage.getItem("my-key");
if (value !== null) {
setStorageValue(value)
}
} catch (e) {
}
};
return
<Button onPress={storeData} title="设置storage!" />
<Button onPress={getData} title="获取storage!" />
<Text style={{color:"#fff"}}>{storageValue}</Text>
}
更多关于HarmonyOS 鸿蒙Next中RN使用AsyncStorage报错的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS 鸿蒙Next中使用React Native的AsyncStorage时,可能会遇到报错问题。通常这是由于鸿蒙系统与React Native的兼容性问题导致的。建议检查以下几点:
- 版本兼容性:确保使用的React Native和AsyncStorage版本与鸿蒙系统兼容。
- 依赖安装:确认AsyncStorage已正确安装并导入到项目中。
- 权限配置:检查是否已正确配置存储权限。
- 调试日志:查看具体报错信息,定位问题所在。
如果问题仍未解决,建议参考鸿蒙官方文档或社区论坛,获取更多技术支持。