Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 8 additions & 33 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**

Code in this file is taken directly from https://reactrouter.com/web/example/basic
*/

import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";

import Products from './Products'
import Logos from './Logos'
// This site has 3 pages, all of which are rendered
// dynamically in the browser (not server rendered).
//
Expand All @@ -19,7 +15,6 @@ import {
// through the site. This preserves the browser history,
// making sure things like the back button and bookmarks
// work properly.

export default function BasicExample() {
return (
<Router>
Expand All @@ -29,15 +24,13 @@ export default function BasicExample() {
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
<Link to="/products">Products</Link>
</li>
<li>
<Link to="/dashboard">Dashboard</Link>
<Link to="/logos">Logos</Link>
</li>
</ul>

<hr />

{/*
A <Switch> looks through all its children <Route>
elements and renders the first one whose path
Expand All @@ -49,41 +42,23 @@ export default function BasicExample() {
<Route exact path="/">
<Home />
</Route>
<Route path="/about">
<About />
<Route path="/products">
<Products />
</Route>
<Route path="/dashboard">
<Dashboard />
<Route path="/logos">
<Logos />
</Route>
</Switch>
</div>
</Router>
);
}

// You can think of these components as "pages"
// in your app.

function Home() {
return (
<div>
<h2>Home</h2>
</div>
);
}

function About() {
return (
<div>
<h2>About</h2>
</div>
);
}

function Dashboard() {
return (
<div>
<h2>Dashboard</h2>
</div>
);
}
34 changes: 34 additions & 0 deletions src/Logos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
class Logo extends React.Component {
constructor() {
super();
this.state = {
response: [],
};
}
componentDidMount() {
this.callApi()
.then((response) => {
this.setState({ response });
})
.catch((err) => console.log(err));
}
callApi = async () => {
const response = await fetch("http://localhost:3001/logo");
const body = await response.json();
if (response.status !== 200) throw Error(body.message);
return body;
};
render() {
let logo = this.state.response
return (
<div>
{logo.map((logo) =>
<p key={logo._id}>{logo.title}</p>
)}
</div>
);
//test comment
}
}
export default Logo;
33 changes: 33 additions & 0 deletions src/Products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";
class Products extends React.Component {
constructor() {
super();
this.state = {
response: [],
};
}
componentDidMount() {
this.callApi()
.then((response) => {
this.setState({ response });
})
.catch((err) => console.log(err));
}
callApi = async () => {
const response = await fetch("http://localhost:3001/products");
const body = await response.json();
if (response.status !== 200) throw Error(body.message);
return body;
};
render() {
let products = this.state.response
return (
<div>
{products.map((product) =>
<p key={product._id}>{product.title}</p>
)}
</div>
);
}
}
export default Products;
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ ReactDOM.render(
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

//comment