<html>
<body>
<h1>Count: <span id="count">0</span></h1>
<button type="button" id="increment">+</button>
<script>
let count = 0;
const currentNode = document.getElementById('count')
document.getElementById('increment').addEventListener('click', () => {
count++;
currentNode.innerText = count;
})
</script>
</body>
</html>
export default function App() {
const [count, setCount] = useState(0);
return (
<>
<h1>Count: {count}</h1>
<button onClick={() => {
setCount(count + 1);
}}>+</button>
</>
)
}
<script>
let count = 0;
</script>
<h1>Count: {count}</h1>
<button onClick={() => {
count++
}}>+</button>
Imperative
Declarative
VanillaJS
React
Svelte
Developer & DX at Monogram
setName("Just changed my name");
db.user.update({;
name: "Just changed my name"
});
// Update props so save button is disabled
props.user.name = "Just changed my name";
<button
on:click={() => {
count++
updateCountInDb(count)
}}
/>
$: updateCountInDb(count)
const [count, setCount] = useState(0)
useEffect(() => {
let unsubscribe = thing.onChange((newCount) => {
setCount(newCount)
})
return unsubscribe
}, [])
const onButtonClick = () => {
setCount(count++);
updateCountInDb(count++);
};
return <button onClick={onButtonClick} />
onMount(() => {
return thing.onChange((newCount) => {
count = newCount
})
})
<button
on:click={() => {
count++
updateCountInDb(count)
}}
/>
$: updateCountInDb(count)
user.name = "Just changed my name"; user.save();
useMemo()
in React using a derived store
svelte-persistent-store
to store user appearance preferenceOn bundle sizes