Search code examples
javascriptreactjsbigint

Large numbers in React


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?


Solution

  • 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.com/MikeMcl/bignumber.js/

    In your case: 1. send string on front-end. 2. get number as string and create BigNumber('9223372036854775800')