Created
December 30, 2020 19:29
-
-
Save dHelmgren/2c447b127acbbecd6ce5f6e5bc276dbc to your computer and use it in GitHub Desktop.
Sample solution for React
This file contains 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
const addStudent = (student) => { | |
axios.post(API_URL_BASE, student) | |
.then((response) => { | |
// What should we do when we know the post request worked? | |
const updatedData = [...studentList, response.data]; | |
setStudentList(updatedData); | |
setErrorMessage(''); | |
}) | |
.catch((error) => { | |
// What should we do when we know the post request failed? | |
setErrorMessage(error.message); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment