Search code examples
reactjsneo4jgrails-orm

Pulling long ids via reactjs truncates ids


I have a query that pulls very large numbers via react. When I request data via curl everything comes back fine. When I use this method:

   getStuff() {
        fetch(SERVER_URL + '/stuff')
            .then(r => r.json())
            .then(json =>
                this.setState({stuff: json})
            )
            .catch(error => console.error('Error connecting to server: ' + error));
    }

I get this JSON string:

[{"id":1244671793987387300}]

when I use Curl (or any other method) I get the correct answer:

[{"id":1244671793987387392}]

Any idea how to circumvent this rounding error before react mangles it?


Solution

  • this is not a react problem, this is a JS issue and the biggest number ir can handle safely https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

    if this is an ID it does not need to be a number, make it a string in the server and everything will be fine.