react-native - React Native 安装包
问题描述
React-Native 新手在这里遇到问题,想知道我是否错过了安装软件包的基本步骤。
我一直在尝试使用 react-native-rsa-native 包(https://github.com/amitaymolko/react-native-rsa-native)
但是我得到
TypeError: undefined is not an object (evaluating '_reactNativeRsaNative.RSA.generateKeys')
我的测试代码是:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { RSA, RSAKeychain } from 'react-native-rsa-native';
export default class App extends React.Component {
componentWillMount() {
RSA.generateKeys(4096) // set key size
.then(keys => {
console.log('4096 private:', keys.private) // the private key
console.log('4096 public:', keys.public) // the public key
});
}
render() {
...
}
}
遵循的步骤是:
expo init rsatest --template blank@sdk-31 --yarn
cd rsatest
yarn add react-native-rsa-native
react-native link react-native-rsa-native
yarn start
react-native-rsa-native 包确实出现在 node_modules 目录中,但是我觉得我错过了一些东西。
有任何想法吗?
解决方案
可能相关的一件事是 componentWillMount 已被弃用。
https://reactjs.org/docs/react-component.html React 文档是 React Native 文档的基础。
同样使用componentWillMount()如果有 fetch 调用,使用 promise,promise 在组件挂载之前不会返回,组件将至少返回一次空。
我建议尝试componentDidMount()
希望这可以帮助
拼写编辑*
推荐阅读
- android - Android custom keyboard layouts switching
- javascript - Push one Row from Table 1 to table 2 and Splice the same row from Table 1 and vice-versa
- java - Maven根本不会运行
- junit - How to compare two objects in Junit
- python - 检查反应分页按钮
- python - Python 多处理 log_to_stderr 在 Windows 上重复
- python - os.listdir print more files than command `ls` but less than `ls -a`
- python - How to convert from a string to a float when taking the data from excel
- json - Proper syntax for adding Rundeck Ansible "Extra Vars"
- javascript - React Native - Callback setstate not work properly in iOS