https://github.com/marcoroth/stimulus-render
[PoC] HTML rendering mechanism for Stimulus Controllers
https://github.com/marcoroth/stimulus-render
dom html javascript jsx stimulus typescript
Last synced: 6 months ago
JSON representation
[PoC] HTML rendering mechanism for Stimulus Controllers
- Host: GitHub
- URL: https://github.com/marcoroth/stimulus-render
- Owner: marcoroth
- License: mit
- Created: 2022-01-19T00:08:02.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-04T13:33:19.000Z (about 3 years ago)
- Last Synced: 2025-05-04T20:46:35.213Z (6 months ago)
- Topics: dom, html, javascript, jsx, stimulus, typescript
- Language: TypeScript
- Homepage:
- Size: 194 KB
- Stars: 21
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stimulus Render
## Getting Started
```bash
yarn add stimulus-render
```
### Counter Example
```html
```
```js
// app/javascript/controllers/counter_controller.js
import { Controller } from '@hotwired/stimulus'
import { useRender, h } from 'stimulus-render'
/** @jsx h */
export default class extends Controller {
static values = { counter: 1 }
connect () {
useRender(this)
}
increment () {
this.counterValue += 1
}
render () {
return (
Count: {this.counterValue}
)
}
}
```
### List/Item Example
```html
-
-
-
```
```js
// app/javascript/controllers/list_controller.js
import { Controller } from '@hotwired/stimulus'
import { useRender, h } from 'stimulus-render'
import { processMarkdown } from 'some-markdown-rendering-package'
/** @jsx h */
export default class extends Controller {
static targets = ['item']
connect () {
useRender(this)
}
renderItemTarget(target) {
return (
{processMarkdown(target.dataset.value)}
)
}
}
```