Last active
November 26, 2024 20:57
-
-
Save jatinkumar725/e0537653245c9424140765df64e11445 to your computer and use it in GitHub Desktop.
Post request in Fetch method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handling Adding the new User to the Server | |
const handleAddUser = async () => { | |
try { | |
const response = await fetch( | |
"https://user-dummy-api.onrender.com/users", | |
{ | |
method: "POST", | |
body: JSON.stringify(userDetails.addModal), | |
headers: { | |
"Content-Type": "application/json" | |
} | |
} | |
); | |
if (response.status === 201) { | |
handleDisplayModal("addModal"); | |
Swal.fire({ | |
title: "User Added Successfully", | |
icon: "success" | |
}); | |
setLoading(true); | |
gettingUsers(); | |
setUserDetails(initialValues); | |
} | |
} catch (error) { | |
console.log(error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment