|
|
|
|
|
by davedx
995 days ago
|
|
For sure. Look at this Svelte 5 example: <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`.