'Unhandled Promise Rejection Network Error in React Native
I want to post data from frontend which used React Native to the mongoDB database. This is my react native code and i used axios. Below function is called when user press saveButton.
const saveButton = async () =>{
console.log("save button");
const newUser = {name,role, email,contact,address,picture}
console.log(newUser);
if(name&&role&&email&&contact&&address&&picture)
{
await axios.post("http://localhost:8070/user/add",newUser).then(()=>{
console.log("Saved data......!")
setname("");
setrole("")
setcontact("");
setemail("");
setaddress("");
setpicture("");
setsaved(true);
})
}else{
console.log("Enter all the fields")
}
}
Unfortunately, there is an error called,
[Unhandled promise rejection: Error: Network Error]
at node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:609:10 in setReadyState
at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:396:6 in __didCompleteResponse
at node_modules\react-native\Libraries\vendor\emitter\_EventEmitter.js:135:10 in EventEmitter#emit
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:414:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:113:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:4 in callFunctionReturnFlushedQueue
When I checked this through postman, it worked. But in react native, this error occurred. Is anyone can help me to solve this error? Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
