Last active
September 2, 2019 11:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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