4 ms·
React: import { useState } from "react"; function Counter() { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count +
by bossyTeacher 9mo ago
React:
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}
----------
Svelte:
<script>
let count = 0;
</script>
<button on:click={() => count += 1}>
Count: {count}
</button>
---------------
React:
function Editor({ initialText }) {
const [text, setText] = useState(initialText);
useEffect(() => {
setText(initialText);
}, [initialText]);
return (
<textarea
value={text}
onChange={e => setText(e.target.value)}
/>
);
}
---------------------
Svelte:
<script>
export let initialText;
let text = initialText;
$: text = initialText;
</script>
<textarea bind:value={text} />
- DaanDL 9mo agoNo one's going to mention VueJS?
- phatskat 9mo agoI enjoy being a Vue main in these discussions, mostly because everyone leaves us alone lol I really enjoy the syntax of Vue over React, and if it’s an application that’s complex enough to warrant something like React I’ll almost always reach for Vue so long as it also meets the requirements.
- division_by_0 9mo agoSeeing Svelte 3/4 code always warms my heart. The ergonomics of `$:` are amazing.