1. primitives for managing state - $state vs useState
2. removal of lifecycle mechanisms - onMount vs componentDidMount
3. replacing lifecycle mechanisms with new primitives - $effect vs useEffect
It's like the Svelte team took a leaf out of React team's book on how to upgrade a framework - this is evident by the way these features are presented as opt-in like how React marketed Hooks as opt-in. I would go on to predict that the upgrade to Runes will just like the upgrade to Hooks. Developers will use it and then love it - because it presents improvements to the way codebases will be structured and maintained just like React did with Hooks. This is really a Hooks moment for Svelte. Good job Rich and the Svelte team!
<script> let time = $state(new Date().toLocaleTimeString());
$effect(() => {
const timer = setInterval(() => {
time = new Date().toLocaleTimeString();
}, 1000);
return () => clearInterval(timer);
});
</script><p>Current time: {time}</p>
Example: https://www.solidjs.com/examples/counter
`onMount` and `onDestroy` feel like really useful, dependable callbacks. `$effect` is scary because if you add a reference to state in it, you can't depend on it being called like `onMount`.
They claim most (but not all) of current usage of `onMount` will be better off using `$effect` instead