Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Last active September 2, 2019 11:42
Show Gist options
  • Save alonbardavid/ab0a3ff71131fffabab5d7a3e1015be9 to your computer and use it in GitHub Desktop.
Save alonbardavid/ab0a3ff71131fffabab5d7a3e1015be9 to your computer and use it in GitHub Desktop.
Controlled components are awesome - and we don't talk about it enough - snippets
function myComponent(selector,label,value,onChange){
let element = document.querySelector(selector);
element.innerHTML=```
<div class="my-element">
<label>${label}</label>
<input></input>
</div>
```
let input = element.querySelector('input');
input.value = value;
input.addEventListener('input', onChange);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment