Last active
July 26, 2020 13:10
-
-
Save Munawwar/6b055a7ca8a1393ccac27a4f68e1f526 to your computer and use it in GitHub Desktop.
Testing function-based framework neverland
This file contains 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
<html lang="en"> | |
<head> | |
<script src="https://unpkg.com/[email protected]/min.js"></script> | |
</head> | |
<body> | |
<div id="app1"></div> | |
<div id="app2"></div> | |
<script type="module"> | |
const { neverland: $, render, html, useState } = neverland; | |
const InputComp = ({ | |
count, | |
setCount | |
}) => { | |
const [characterCount, setCharacterCount] = useState(0); | |
return html`<input | |
oninput=${({ target: { value }}) => { | |
setCharacterCount(value.length); | |
setCount(count + 1); | |
}} | |
/> (${ characterCount })`; | |
}; | |
const App = $(() => { | |
const [count, setCount] = useState(0); | |
const [components] = useState([1, 2]); | |
return html`${ | |
components.map(() => html` | |
<div id="count">${count}</div> | |
${$(InputComp)({ count, setCount })} | |
<button type="button" onclick=${() => setCount(count + 1)}> | |
Increment | |
</button> | |
`) | |
}`; | |
}); | |
render(document.getElementById('app1'), App()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment