Browse Source

Add Backend call from frontend

pull/10/head
garritfra 5 years ago
parent
commit
c6b9aa226a
  1. 26
      frontend/src/App.tsx

26
frontend/src/App.tsx

@ -2,14 +2,34 @@ import React, { useState, useEffect } from "react";
import axios from "axios";
export default function App() {
let [blocks, setBlocks] = useState([]);
let backendUrl: string = process.env.BACKEND_ADDRESS!;
if (backendUrl === undefined) {
throw Error("backend address not specified in ENV variable");
}
console.log(backendUrl);
async function fetchBlocks() {
let result = await axios(backendUrl);
return result.data.Blocks;
}
useEffect(() => {
axios.get("https://baconipsum.com/api/?type=meat-and-filler").then(res => {
console.log(res.data);
fetchBlocks().then(blocks => {
setBlocks(blocks);
});
}, []);
let blocksComponent = blocks.map(block => {
return <li key={block.hash}>{block.hash}</li>;
});
return (
<div>
<h1>Hello from App!</h1>
<h1>{blocksComponent}</h1>
</div>
);
}

Loading…
Cancel
Save