Created
May 7, 2025 14:10
-
-
Save paoloricciuti/b917cdbbf08688337d85fbfcc0780fb2 to your computer and use it in GitHub Desktop.
Signals from Scratch
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
| <button id="btn">0</button> | |
| <input id="input" /><input type="checkbox" id="check" /> |
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 state = $state({ | |
| count: 0, | |
| text: "", | |
| show: false, | |
| }); | |
| $effect(()=>{ | |
| if(state.show){ | |
| btn.innerText = `${state.text} ${state.count}` | |
| } | |
| }); | |
| $effect(()=>{ | |
| input.value = state.text; | |
| }); | |
| btn.addEventListener("click", ()=>{ | |
| state.count++; | |
| }) | |
| input.addEventListener("input", (e)=>{ | |
| state.text = e.target.value; | |
| }) | |
| check.addEventListener('change', (e)=>{ | |
| state.show = e.target.checked; | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
End result