react-native - 如何返回结果值而不是承诺?
问题描述
我试图从承诺中获得返回值,但我做不到。
我正在从“react-native-sha256”导入 { sha256 }
const sha256 = sha256(keytohash);
return sha256;
承诺 {_40: 0, _65: 0, _55: null, _72: null} <<< 这是我在 console.log 时得到的
我也试过:
const sha256 = async () => {
const key = await sha256(keytohash).then(hash => (hash));
return key;
};
return sha256;
承诺 {_40: 0, _65: 0, _55: null, _72: null} <<< 这是我在 console.log 时得到的
反正有没有让我得到哈希值而不是承诺对象?
解决方案
尝试!
const getSha256 = async () => {
const key = await sha256(keytohash)
return key;
}
console.log(getSha256())
您返回了异步函数而不是值。
Math.random = function
Math.random() = value
您需要使用 await 来等待 promise.resolve。
推荐阅读
- javascript - 在控制台中打印数组时长度错误
- excel - 在 MS Excel 中验证重复输入字符的顺序
- python - 如何在 python 字典中拥有键、键值对和唯一的键?
- elasticsearch - 迁移到弹性搜索 6.8 后的字符编码问题
- reactjs - 如何处理 useReducer() 中的不纯函数
- java - 当我运行我的程序时,一个额外的输出即将到来
- terraform - 如何输出使用 for_each 创建的资源的多个实例的属性?
- mysql - Mysql查询具有多个状态的整体
- javascript - 按下面板后,其内容不显示
- android - 如何在 Unity 中为 Android 设备支持不同的恶意密度?