react-native - 使用 sha256 反应原生
问题描述
我正在尝试使用这个react-native 库来进行 sha256 散列。这是我的代码:
import React, {Component} from 'react'
import { AppRegistry, Text, View} from 'react-native'
import {sha256} from 'react-native-sha256'
export default class CyrptoTest extends Component {
constructor(props){
super(props)
}
componentDidMount(){
sha256("test").then(hash => {
console.log(hash)
})
}
render(){
return(
<View style={{padding:30}}>
<Text>this is CryptoTest 1</Text>
</View>
)
}
}
我收到此错误:undefined is not an object (evaluating 'sha256lib.sha256')
我不知道这是为什么或如何解决此问题,感谢任何帮助,谢谢
PS:在我做任何这些之前,我首先在命令行中运行它:
yarn add react-native-sha256
react-native link
为了在我的 Mac 上的模拟器中运行该应用程序,我这样做:
react-native start
react-native run-ios
解决方案
我遇到了同样的问题,在我的情况下,我使用的是 react native cli debug server host & port for device,它通过 ./gradlew clean 和重新编译手机上的应用程序来解决。
推荐阅读
- python - 列表输入和创建的列表不同
- wordpress - 在不同的视图上使用不同的插件(手机、电脑视图)
- java - 休眠保存问题 - 保存在本地机器上工作正常,但在服务器上失败
- reactjs - 如何在 react-redux 中正确键入映射到道具的动作创建者
- java - 使用 Math.sqrt() 作为参数时,List contains 方法返回 false
- java - 获取 18-99 范围而不是 0-100 范围
- android - 如何使用 Koin 从演示者注入交互器
- string - Scala 2.12.7 中字符串的奇怪错误
- ruby-on-rails - 每当 gem 指向应用程序时间时设置
- gcc - 如何为 GCC 链接 Libbluetooth?