Getting this {"_h": 0, "_i": 0, "_j": null, "_k": null} instead of a Number in React Native

huangapple go评论111阅读模式
英文:

Getting this {"_h": 0, "_i": 0, "_j": null, "_k": null} instead of a Number in React Native

问题

我正在尝试创建一个函数,该函数返回服务器时间戳字段值与即时客户端时间戳之间的时间差!当我尝试将结果记录到控制台时,它运行正常

但是!!当我想要返回该整数结果时,它显示这个"{"_h": 0, "_i": 0, "_j": null, "_k": null}" !!! 你有任何建议为什么会发生这种情况?

我尝试了一些无意义的解决方案,但对我没有用!

英文:

I'm trying to make a function that returns a time difference between a server timestamp field's value and an instant client timestamp! When I try to the log the result to the console it works fine

Getting this {"_h": 0, "_i": 0, "_j": null, "_k": null} instead of a Number in React Native

BUT!! when I want to return that int result .. it shows this "{"_h": 0, "_i": 0, "_j": null, "_k": null}" !!! do you have any suggestion why this is happening ?

I tried some of non-sense solutions and nothing worked for me!

答案1

得分: 4

loggingTimeDifference 是一个 async 函数,因此它将始终返回一个 promise。要获取实际结果,您必须要么等待它,要么将回调链接到该 promise。

使用等待的调用如下所示:

const result = await loggingTimeDifference();
console.log(result);

以及链接方式:

loggingTimeDifference().then((result) => console.log(result));
英文:

loggingTimeDifference is an async function, so it'll always return a promise.
To get actual result you have to either await it or chain callback to the promise.

Call with awaiting would look like this:

const result = await loggingTimeDifference();  
console.log(result);  

And chaining:

loggingTimeDifference().then((result) => console.log(result));  

huangapple
  • 本文由 发表于 2023年6月8日 17:34:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430469.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定