Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create api service #5

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions client/src/components/CardsComponent.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useState } from "react";
import Card from "./Card";
import axios from "axios";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
import InputLabel from "@material-ui/core/InputLabel";
import MenuItem from "@material-ui/core/MenuItem";
import { makeStyles } from "@material-ui/core";
import HashLoader from "react-spinners/HashLoader";
import { api } from "../services/api";

const useStyles = makeStyles((theme) => ({
formControl: {
Expand All @@ -28,11 +28,9 @@ const CardsComponent = () => {
const [company, setCompany] = useState("All");
const [loader, setLoader] = useState(true);

const apiURL = "https://allhacks.herokuapp.com";

useEffect(() => {
const fetchData = async () => {
const results = await axios.get(`${apiURL}/hacks`);
const results = await api.get("/hacks");
setData(results.data.hackathon);
setLoader(false);
};
Expand All @@ -42,7 +40,7 @@ const CardsComponent = () => {
const handleChange = (e) => {
setCompany(e.target.value);
const customData = async () => {
const results = await axios.get(`${apiURL}/${e.target.value}`);
const results = await api.get(`/${e.target.value}`);
setData(results.data.hackathon);
};
customData();
Expand Down
5 changes: 5 additions & 0 deletions client/src/services/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import axios from "axios";

const apiURL = "https://allhacks.herokuapp.com";

export const api = axios.create({baseURL: apiURL});