You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
704 B
33 lines
704 B
import React, { useState, useEffect } from "react"; |
|
import axios from "axios"; |
|
|
|
export default function BlockList() { |
|
let [blocks, setBlocks] = useState([]); |
|
|
|
let backendUrl = process.env.BACKEND_ADDRESS!; |
|
|
|
if (backendUrl === undefined) { |
|
throw Error("backend address not specified in ENV variable"); |
|
} |
|
|
|
const blocksComponent = blocks.map(block => { |
|
return <li key={block.hash}>{block.hash}</li>; |
|
}); |
|
|
|
async function fetchBlocks() { |
|
let result = await axios(backendUrl); |
|
return result.data.Blocks; |
|
} |
|
|
|
useEffect(() => { |
|
fetchBlocks().then(blocks => { |
|
setBlocks(blocks); |
|
}); |
|
}, []); |
|
|
|
return ( |
|
<div> |
|
<h1>{blocksComponent}</h1> |
|
</div> |
|
); |
|
}
|
|
|