I setup my local server using express.js
, That simply handle request and return simple message.
app.get('/hello', (req, res) => {
res.send('Hello world !');
});
I executed server and test it on web-browser, it works well.
Simply I want to do that on my react-native
app.
this is my action.js
file
import axios from 'axios';
exports.helloButtonPressAct = (email, password) => {
return function (dispatch) {
return axios.get('http://localhost:3000/hello')
.then(function (response) {
console.log(response);
// and create action obj here
// dispatch(someAction(...))
})
.catch(function (error) {
throw error;
console.log(error);
});
};
};
It only return catch()
result.
Possible Unhandled Promise Rejection (id: 0): Network Error Error: Network Error at createError ...
Maybe something wrong but I couldn't find what is it.
How can I fix this?
Solved.
return axios.get('http://localhost:3000/hello')
to
return axios.get('http://10.0.0.2:3000/hello')
and It works.
In Android emulator, the localhost
refers its device.
https://github.com/facebook/react-native/issues/10404
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With