Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf authored May 26, 2024
1 parent d05c2cd commit 5b18cf8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,31 @@ npm install @socketsupply/tonic

```js
import Tonic from '@socketsupply/tonic'
```

You can use functions as components. They can be async or even an async generator function.

```js
async function MyGreeting () {
const data = await (await fetch('https://example.com/data')).text()
return this.html`<h1>Hello, ${data}</h1>`
}
```

Or you can use classes. Every class must have a render method.

``js
class MyGreeting extends Tonic {
render () {
return this.html`<div>Hello, World.</div>`
async * render () {
yield this.html`<div>Loading...</div>`

const data = await (await fetch('https://example.com/data')).text()
return this.html`<div>Hello, ${data}.</div>`
}
}
```
```js
Tonic.add(MyGreeting, 'my-greeting')
```

Expand Down

0 comments on commit 5b18cf8

Please sign in to comment.