Ameen
Front End Web Developer
I like Svelte but that code comparison is kinda staged. A fair one would use hooks on React, also would properly clear the interval in Svelte too and used the component created inside other component as well.
For React can be done this way (and clearing the interval):
function Timer() {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setSeconds(seconds + 1);
}, 1000);
return () => clearInterval(interval);
});
return <span>Seconds: {seconds}</span>;
}
Either way, Svelte is really nice and I'd recommend it every day.
Great read. It has everything I expected to see when I opened the article. Very well written Ameen
Keep up the good work.
Mattia Sinisi
Full-Stack Developer
Finally, give Svelte some love!