Skip to content

Instantly share code, notes, and snippets.

@paoloricciuti
Created May 7, 2025 14:10
Show Gist options
  • Select an option

  • Save paoloricciuti/b917cdbbf08688337d85fbfcc0780fb2 to your computer and use it in GitHub Desktop.

Select an option

Save paoloricciuti/b917cdbbf08688337d85fbfcc0780fb2 to your computer and use it in GitHub Desktop.
Signals from Scratch
<button id="btn">0</button>
<input id="input" /><input type="checkbox" id="check" />
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;
});
@paoloricciuti
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment