From 944fefa06c375dc475d4b374a2acee9a81943de8 Mon Sep 17 00:00:00 2001 From: Johnny Rice Date: Thu, 20 Aug 2020 18:32:28 -0400 Subject: [PATCH 1/2] Provide ajax detail starter --- src/App.js | 36 +++++++++--------------------------- src/Logos.js | 8 ++++++++ src/Products.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 src/Logos.js create mode 100644 src/Products.js diff --git a/src/App.js b/src/App.js index efafdbd..77b5976 100644 --- a/src/App.js +++ b/src/App.js @@ -1,8 +1,3 @@ -/** - - Code in this file is taken directly from https://reactrouter.com/web/example/basic - */ - import React from "react"; import { BrowserRouter as Router, @@ -11,6 +6,9 @@ import { 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). // @@ -29,10 +27,10 @@ export default function BasicExample() { Home
  • - About + Products
  • - Dashboard + Logos
  • @@ -49,11 +47,11 @@ export default function BasicExample() { - - + + - - + + @@ -70,20 +68,4 @@ function Home() {

    Home

    ); -} - -function About() { - return ( -
    -

    About

    -
    - ); -} - -function Dashboard() { - return ( -
    -

    Dashboard

    -
    - ); } \ No newline at end of file diff --git a/src/Logos.js b/src/Logos.js new file mode 100644 index 0000000..3c49978 --- /dev/null +++ b/src/Logos.js @@ -0,0 +1,8 @@ +import React from 'react' + + +export default () => { + return ( +
    Logos Place holder
    + ) +} \ No newline at end of file diff --git a/src/Products.js b/src/Products.js new file mode 100644 index 0000000..ce27ed2 --- /dev/null +++ b/src/Products.js @@ -0,0 +1,35 @@ +import React from 'react' + +class Products extends React.Component { + constructor () { + super() + this.state = { + results: [] + } + } + + componentDidMount() { + this.callApi() + .then(res => this.setState({ response: res.express })) + .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 () { + return ( +
    +
    Products Place holder
    +
    {this.state.response}
    +
    + ) + } +} + +export default Products \ No newline at end of file From 2602809bd23389f58f4e739236e9d23bbd710f49 Mon Sep 17 00:00:00 2001 From: Ziedah Ward Date: Wed, 30 Sep 2020 20:22:58 -0400 Subject: [PATCH 2/2] Changes to products.js and package.json --- package-lock.json | 14 +++++++++++++- src/Products.js | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d5340b..81f569a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3582,6 +3582,8 @@ }, "@testing-library/jest-dom": { "version": "4.2.4", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-4.2.4.tgz", + "integrity": "sha512-j31Bn0rQo12fhCWOUWy9fl7wtqkp7In/YP2p5ZFyRuiiB9Qs3g+hS4gAmDWONbAHcRmVooNJ5eOHQDCOmUFXHg==", "requires": { "@babel/runtime": "^7.5.1", "chalk": "^2.4.1", @@ -3606,6 +3608,8 @@ }, "@testing-library/react": { "version": "9.5.0", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-9.5.0.tgz", + "integrity": "sha512-di1b+D0p+rfeboHO5W7gTVeZDIK5+maEgstrZbWZSSvxDyfDRkkyBE1AJR5Psd6doNldluXlCWqXriUfqu/9Qg==", "requires": { "@babel/runtime": "^7.8.4", "@testing-library/dom": "^6.15.0", @@ -3613,7 +3617,9 @@ } }, "@testing-library/user-event": { - "version": "7.2.1" + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-7.2.1.tgz", + "integrity": "sha512-oZ0Ib5I4Z2pUEcoo95cT1cr6slco9WY7yiPpG+RGNkj8YcYgJnM7pXmYmorNOReh8MIGcKSqXyeGjxnr8YiZbA==" }, "@types/babel__core": { "version": "7.1.9", @@ -12632,6 +12638,8 @@ }, "react": { "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react/-/react-16.13.1.tgz", + "integrity": "sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==", "requires": { "loose-envify": "^1.1.0", "object-assign": "^4.1.1", @@ -12838,6 +12846,8 @@ }, "react-dom": { "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.13.1.tgz", + "integrity": "sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==", "requires": { "loose-envify": "^1.1.0", "object-assign": "^4.1.1", @@ -12903,6 +12913,8 @@ }, "react-scripts": { "version": "3.4.3", + "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-3.4.3.tgz", + "integrity": "sha512-oSnoWmii/iKdeQiwaO6map1lUaZLmG0xIUyb/HwCVFLT7gNbj8JZ9RmpvMCZ4fB98ZUMRfNmp/ft8uy/xD1RLA==", "requires": { "@babel/core": "7.9.0", "@svgr/webpack": "4.3.3", diff --git a/src/Products.js b/src/Products.js index ce27ed2..d5352d5 100644 --- a/src/Products.js +++ b/src/Products.js @@ -4,13 +4,15 @@ class Products extends React.Component { constructor () { super() this.state = { - results: [] + response : [] } } componentDidMount() { this.callApi() - .then(res => this.setState({ response: res.express })) + .then((response) => { + this.setState({ response: response.length + ' items found' }) + } ) .catch(err => console.log(err)); }