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
Add a ment  | 

4 Answers 4

Reset to default 6

To 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