import { Component, h } from "preact"; import { useEffect, useState } from "preact/hooks"; import * as style from "./style.css"; export interface DatasetProps { name: string, } export interface Datapoint { id: number, devicename: string, value: number, timestamp: string, } export interface DatasetState { data: Datapoint[], } class Dataset extends Component { constructor(){ super(); this.state = { data: [] }; } async componentDidMount() { var devicesResponse = await fetch(`/api/device/${this.props.name}`); this.setState({ data: await devicesResponse.json() as Datapoint[] }) } // Lifecycle: Called just before our component will be destroyed componentWillUnmount() { // stop when not renderable } render() { var deviceLinks = this.state.data.map((d) =>
{d.devicename},{d.value},{d.timestamp}
) return
{this.props.name}{deviceLinks}
; } } export default Dataset;