import { Controller } from "stimulus"; export default class extends Controller { static targets = [ "clock" ]; static values = { time: String, } connect() { this.load(); let controller = this; this.clockInterval = setInterval(function() { controller.load(); }, 20 * 1000); } disconnect() { clearInterval(this.clockInterval); } load() { fetch(`/clock`) .then(response => response.text()) .then(html => { this.clockTarget.innerHTML = html; }); } }