首页 > 解决方案 > 在 expo 应用程序中使用库时 react-native-Uuid-generator 崩溃

问题描述

我想在使用 expo cli 构建的 ReactNative 应用程序中生成一个 uuid。当我从安装UUIDGeneratorReact-native-uuid-generator,我得到undefined is not an object(evaluating ‘RNUUIDGenerator.getRandomUUID’..)

尝试了两个 diff 库,react-native-uuidReact-native-uuid-generator,同样的问题,认为它可能与 expo 不喜欢链接命令有关。

UUIDGenerator.getRandomUUID().then(uuid => console.log(uuid));

期望打印新的 uuid,实际上收到错误消息。

标签: react-nativeexpouuid

解决方案


react-native-uuid与世博会合作。

npm install react-native-uuid --save

import uuid from 'react-native-uuid';

然后像

const uuid = uuid.v1();

推荐阅读