'use strict'; import { h, render, Component } from 'preact'; class Pageviews extends Component { constructor(props) { super(props) this.state = { records: [] } this.fetchRecords = this.fetchRecords.bind(this); this.fetchRecords(props.period); } componentWillReceiveProps(newProps) { if(this.props.period != newProps.period) { this.fetchRecords(newProps.period) } } fetchRecords(period) { return fetch('/api/pageviews?period=' + period, { credentials: 'include' }).then((r) => { if( r.ok ) { return r.json(); } }).then((data) => { this.setState({ records: data }) }); } render() { const tableRows = this.state.records.map( (p, i) => ( {i+1} {p.Path} {p.Count} {p.CountUnique} )); return (

Pageviews

{tableRows}
# URL Pageviews Unique
) } } export default Pageviews