[PoC] HTML rendering mechanism for Stimulus Controllers
TypeScriptMIT
Stimulus Render
Getting Started
yarn add stimulus-render
Counter Example
<divdata-controller="counter"></div>
// app/javascript/controllers/counter_controller.jsimport{Controller}from'@hotwired/stimulus'import{useRender,h}from'stimulus-render'/** @jsx h */exportdefaultclassextendsController{staticvalues={counter: 1}connect(){useRender(this)}increment(){this.counterValue+=1}render(){return(<divid="counter"><buttondata-action="click->counter#increment">
Count: {this.counterValue}</button></div>)}}
List/Item Example
<divdata-controller="list"><ul><lidata-list-target="item" data-value="# Title 1"></li><lidata-list-target="item" data-value="**Two Bold**"></li><lidata-list-target="item" data-value="[Three Link](https://github.com/marcoroth/stimulus-render)"></li></ul></div>
// app/javascript/controllers/list_controller.jsimport{Controller}from'@hotwired/stimulus'import{useRender,h}from'stimulus-render'import{processMarkdown}from'some-markdown-rendering-package'/** @jsx h */exportdefaultclassextendsController{statictargets=['item']connect(){useRender(this)}renderItemTarget(target){return(<span>{processMarkdown(target.dataset.value)}</span>)}}