all repos — h3 @ c310cd0dea3b30ec47b42678e77dbd726bd890f3

A tiny, extremely minimalist JavaScript microframework.

docs/md/quick-start.md

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
## Quick Start

Start with a minimal HTML file like this one, and include an `app.js` script. That will be the entry point of your application:

```html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>H3</title>
    <meta name="description" content="My little H3-powered app" />
    <meta name="author" content="Fabio Cevasco" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body>
    <script src="js/app.js"></script>
  </body>
</html>
```

Then, inside your `app.js` file, import `h3.js`, which should be accessible somewhere in your app:

```js
import h3 from "./h3.js";
```

This will work in [every modern browser except Internet Explorer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). You don't need a transpiler, you don't need something to convert your beautiful ES6 code back to cluncky ES5.

Unless your company tells you to, do yourself a favor and don't support IE. It's 2020, even [Microsoft moved on](https://www.theverge.com/2020/1/15/21066767/microsoft-edge-chromium-new-browser-windows-mac-download-os), and now ES6 modules work in all major browsers.

After importing the `h3` object, you can start developing your SPA. A bare minimum SPA is comprised by a single component passed to the `h3.init()` method:

```js
// A simple component printing the current date and time
// Pressig the Refresh button causes the applicationn to redraw
// And updates the displayed date/dime.
const Page = () => {
  return h3("main", [
    h3("h1", "Welcome!"),
    h3("p", `The current date and time is ${new Date()}`),
    h3("button", {
      onclick: () => h3.redraw()
    }, "Refresh")
  ]);
}
// Initialize your SPA
h3.init(Page);
```