Skip to content

Instantly share code, notes, and snippets.

@dHelmgren
Created December 30, 2020 19:29
Show Gist options
  • Save dHelmgren/2c447b127acbbecd6ce5f6e5bc276dbc to your computer and use it in GitHub Desktop.
Save dHelmgren/2c447b127acbbecd6ce5f6e5bc276dbc to your computer and use it in GitHub Desktop.
Sample solution for React
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