在线 Playground 测试
state 简单状态
vue
const count = ref(0);
const increment = () => (count.value += 1);
react
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);
state 复杂状态
vue
state = reactive({
value: 0,
});
state.value = 1;
react
const [state, setState] = useReducer((prev, { ...next }) => ({ ...prev, ...next }), {
value: 0,
});
setState({ value: 1 });