Last active
October 10, 2024 13:58
-
-
Save shiftyp/4f8d99719c1a6ee0c723fd19a1f2d1f1 to your computer and use it in GitHub Desktop.
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
const div = document.createElement('div') | |
const input = document.createElement('input') | |
input.setAttribute('type', 'text') | |
input.addEventListener('change', (e) => { | |
if (text === '') { | |
return updateDiv({ text, className: 'hidden'}) | |
} | |
updateDiv(text, className: 'my-class') | |
}); | |
const updateDiv = ({ text, className }) => { | |
div.innerText = text | |
if (className !== div.getAttribute('class')) { | |
div.setAttribute('class', className) | |
} | |
} | |
document.body.appendElement(div) | |
document.body.appendElement(input) | |
updateDiv({ text: 'I\'m some text', className: 'my-class' }) |
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
import { render, useSignal } from 'preact' | |
const Component = () => { | |
const text = useSignal('I\'m some text') | |
return ( | |
<> | |
<div className={text.value ? 'my-class' : 'hidden'}> | |
{text.value} | |
</div> | |
<input onChange={(e) => text.value = e.target.value} type="text" /> | |
</> | |
) | |
} | |
render(<Component />, document.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment