JSFiddle - React, Tailwind, and code Playground

by tonyleeper

JavaScript

'use strict';
class Spa {
	constructor(Component, spec) {
        this.render(new Component(spec));
    }
    
    render(component) {
    	// remove old component
        if (this.component && typeof this.component.dispose == 'function') {
        	this.component.dispose();
        }
        
        // create new component
        document.body.innerHTML = component.render();
        this.component = component;
    }
}

class HelloWorld {
	constructor(spec) {
        this.spec = spec;
    }
    
    render() {
    	return `<app>Hello world!</app>`;
    }
    
    dispose() {
        
    }
}

new Spa(HelloWorld);