-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from alecspringel/posts
Posts
- Loading branch information
Showing
6 changed files
with
90 additions
and
172 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import axios from "axios"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
const Fetch = ({ type, url = process.env.REACT_APP_SERVER_URL, endpoint }) => { | ||
const [res, setRes] = useState({ data: null, errors: null, loading: false }); | ||
useEffect(() => { | ||
setRes({ ...res, loading: true }); | ||
axios[type](url + endpoint, { withCredentials: true }) | ||
.then((response) => { | ||
setRes({ ...res, data: response.data, loading: false }); | ||
}) | ||
.catch((err) => { | ||
if (err.response && err.response.data) { | ||
// Set the errors provided by our API request | ||
console.log(err.response.data.errors); | ||
setRes({ ...res, errors: err.response.data.errors, loading: false }); | ||
} else { | ||
setRes({ | ||
...res, | ||
errors: [ | ||
"There was an error creating the course. Please try again.", | ||
], | ||
loading: false, | ||
}); | ||
} | ||
}); | ||
}, []); | ||
return res; | ||
}; | ||
|
||
export default Fetch; |
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
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
This file was deleted.
Oops, something went wrong.
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