It's been a while since the last time I used React. Sticking with Vue is good but I feel like I should try React again, we got some frameworks for it too like Next.js, Preact and Remix. Which one should I try? But I think I should try the library first before them. I found some guides to help me migrate from Vue to React. Vue feels more natural to me, React is a bit more declarative but I think that's the point of it, have more control of what you're writing.
<script lang="ts" setup>
import { ref } from 'vue';
const count = ref(0);
function operation(op: 'add' | 'sub') {
if (op === 'add') count.value++;
else count.value--;
}
</script>
<template>
<div>
<h1>{{ count }}</h1>
<button @click="operation('add')">Add</button>
<button @click="operation('sub')">Subtract</button>
</div>
</template>
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
function operation(op: 'add' | 'sub') {
if (op === 'add') setCount(count + 1);
else setCount(count - 1);
}
return (
<div>
<h1>{count}</h1>
<button onClick={() => operation('add')}>Add</button>
<button onClick={() => operation('sub')}>Subtract</button>
</div>
)
}