DEV Community

Discussion on: How to get data from an MySQL database in React Native

Collapse
 
saulojoab profile image
Saulo Joab

That's because we only created the "users" route on this tutorial. Like this:

app.get('/users', function (req, res) {

If you want to create the homepage route, you gotta add the '/' char, like this:

app.get('/', function (req, res) {
Collapse
 
zackthedev profile image
mPH4NT0M • Edited

I am trying to fetch the data from '/users' and display it in the homepage.

fetch(){ 
    fetch('http://localhost:3000/users')
      .then(response => response.json())
      .then(output => (this.setState({output}))
      )} 

Thread Thread
 
saulojoab profile image
Saulo Joab

You can't use localhost because you're running the app in your cellphone. The server is running on your computer. If you use locahost the app will understand that the server is running on your cellphone, which is not correct. Here's how you should do it:

async fetch(){ 
    await fetch('http://yourComputerIPhere:3000/users')
      .then(response => response.json())
      .then(output => (this.setState({output}))
    )}