diff --git a/src/App.js b/src/App.js
index 72019dd..2725f28 100644
--- a/src/App.js
+++ b/src/App.js
@@ -16,7 +16,7 @@ function App() {
-
+
@@ -28,7 +28,7 @@ function App() {
-
+
diff --git a/src/Components/CounterExample.js b/src/Components/CounterExample.js
index a9c29be..ea19965 100644
--- a/src/Components/CounterExample.js
+++ b/src/Components/CounterExample.js
@@ -8,12 +8,12 @@ function CounterExample() {
{count}
- setCount(count + 1)}>
+ setCount(count + 1)}>
Plus
-
- setCount(count - 1)}>
+
+ setCount(count - 1)}>
Minus
-
+
)
}
diff --git a/src/Components/Footer.js b/src/Components/Footer.js
index 65f5c43..877db8e 100644
--- a/src/Components/Footer.js
+++ b/src/Components/Footer.js
@@ -3,7 +3,7 @@ import React from 'react';
function Footer() {
return (
)
}
diff --git a/src/Components/Header.js b/src/Components/Header.js
index fc68411..a912783 100644
--- a/src/Components/Header.js
+++ b/src/Components/Header.js
@@ -1,11 +1,11 @@
import React from 'react';
+import { Link } from 'react-router-dom';
import Navigation from './Navigation'
function Header() {
return (
)
diff --git a/src/Components/Loader.js b/src/Components/Loader.js
index 5e03fcc..e756b47 100644
--- a/src/Components/Loader.js
+++ b/src/Components/Loader.js
@@ -3,7 +3,7 @@ import React from 'react'
function Loader() {
return (
)
}
diff --git a/src/Components/NavigationMenu.js b/src/Components/NavigationMenu.js
index f35330c..e9e007e 100644
--- a/src/Components/NavigationMenu.js
+++ b/src/Components/NavigationMenu.js
@@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
function NavigationMenu(props) {
return (
-
+
{props.product.description}
-
-
- View
+
+
+
diff --git a/src/Hooks/HTTPRequest.js b/src/Hooks/HTTPRequest.js
index a28d526..9d10344 100644
--- a/src/Hooks/HTTPRequest.js
+++ b/src/Hooks/HTTPRequest.js
@@ -1,28 +1,28 @@
-import React, { useState, useEffect } from 'react'
-import axios from 'axios'
+import { useState, useEffect } from 'react';
+import axios from 'axios';
export function useAxiosGet(url) {
- const [products, setProducts] = useState({
+ const [request, setRequest] = useState({
loading: false,
data: null,
error: false
});
useEffect(() => {
- setProducts({
+ setRequest({
loading: true,
data: null,
error: false
});
axios.get(url).then(response => {
- setProducts({
+ setRequest({
loading: false,
data: response.data,
error: false
});
}).catch(() => {
- setProducts({
+ setRequest({
loading: false,
data: null,
error: true
@@ -30,6 +30,6 @@ export function useAxiosGet(url) {
});
}, [url]);
- return products;
+ return request;
}
diff --git a/src/Views/About.js b/src/Views/About.js
index 982e98f..862303b 100644
--- a/src/Views/About.js
+++ b/src/Views/About.js
@@ -2,10 +2,10 @@ import React from 'react'
function About() {
return (
-
+
About us
This is the about page content.
-
+
);
}
diff --git a/src/Views/Home.js b/src/Views/Home.js
index 36b3119..fa2adec 100644
--- a/src/Views/Home.js
+++ b/src/Views/Home.js
@@ -1,19 +1,19 @@
-import React from 'react'
+import React from 'react';
import Loader from '../Components/Loader';
import ProductCard from '../Components/ProductCard';
import { useAxiosGet } from '../Hooks/HTTPRequest';
function Home() {
const url = 'https://5f7b89e100bd740016909a8a.mockapi.io/products?page=1&limit=10';
+ const products = useAxiosGet(url);
let content = null;
- let products = useAxiosGet(url);
if (products.loading) {
content =
}
if (products.error) {
- content = There was an error. Please refresh or try again.
+ content = There was an error. Please refresh or try again.
}
if (products.data) {
diff --git a/src/Views/Product.js b/src/Views/Product.js
index ed388cd..e255ae6 100644
--- a/src/Views/Product.js
+++ b/src/Views/Product.js
@@ -1,40 +1,14 @@
-import React, { useState, useEffect } from 'react'
-import axios from 'axios'
+import React from 'react'
import { useParams } from 'react-router-dom';
import Loader from '../Components/Loader';
+import { useAxiosGet } from '../Hooks/HTTPRequest';
function Product() {
const { id } = useParams();
const url = `https://5f7b89e100bd740016909a8a.mockapi.io/products/${id}`;
- const [product, setProduct] = useState({
- loading: false,
- data: null,
- error: false
- });
+ const product = useAxiosGet(url);
let content = null;
- useEffect(() => {
- setProduct({
- loading: true,
- data: null,
- error: false
- });
-
- axios.get(url).then(response => {
- setProduct({
- loading: false,
- data: response.data,
- error: false
- });
- }).catch(() => {
- setProduct({
- loading: false,
- data: null,
- error: true
- });
- });
- }, [url]);
-
if (product.loading) {
content =
}