admin管理员组文章数量:1265450
I have a Bigint column in my Table in SQL server as a Primary Key and when I request from a client with axios
or fetch
in React, it has a problem with ids like 9223372036854775800
and converts all of them to 9223372036854776000
!!!,
How can I fix that?
I have a Bigint column in my Table in SQL server as a Primary Key and when I request from a client with axios
or fetch
in React, it has a problem with ids like 9223372036854775800
and converts all of them to 9223372036854776000
!!!,
How can I fix that?
Share Improve this question edited May 5, 2019 at 17:13 oguz ismail 50.8k16 gold badges58 silver badges78 bronze badges asked May 5, 2019 at 17:11 wakiwikiwakiwiki 2232 gold badges4 silver badges14 bronze badges 5- 3 you should not use it as number, use string. and it's not related to reactjs. it's javascript issue. – Ehsan Commented May 5, 2019 at 17:13
- 1 Possible duplicate of What is JavaScript's highest integer value that a number can go to without losing precision? – adiga Commented May 5, 2019 at 17:33
-
1
Send a string from the server and use
BigInt
– adiga Commented May 5, 2019 at 17:34 - @adiga how can I use BigInt in react? – wakiwiki Commented May 5, 2019 at 18:52
- Click the link the in the ment. – adiga Commented May 5, 2019 at 19:08
4 Answers
Reset to default 6To enable the BigInt in React as of now you have to add this ment to your code:
/* global BigInt */
Please, refer to this.
For resolve this problem you can send on the front-end string instead of number. Native js not support big number. If you want work on front-end with big number, you can use bignumber js library: https://github./MikeMcl/bignumber.js/
In your case:
1. send string on front-end.
2. get number as string and create BigNumber('9223372036854775800')
In your MySQL connection config, give a property
supportBigNumbers: true,
add es2020 support in package.json
eslint config block like:
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"env": {
"es2020": true
}
}
and dont forget to restart your server
本文标签: javascriptLarge numbers in ReactStack Overflow
版权声明:本文标题:javascript - Large numbers in React - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741035018a2328064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论