React Learning Experience: React vs Vue
Translated from Chinese by AI (deepseek-chat). It may differ from the original.
Preface: For a long time, Vue has been my primary frontend framework. From template syntax and reactive data to the Composition API, Vue's "out-of-the-box" and "hand-holding experience" have accompanied me through many projects. Recently, I systematically studied Teacher Xiaoman's React Docs documentation, officially adding React as my second frontend framework.
Although I've just finished the entire tutorial and haven't yet encountered real-world pitfalls in commercial projects, the biggest takeaway from this systematic learning is: React and Vue have fundamentally different underlying worldviews.
Below, I'll compare the knowledge structure of this React documentation (basic syntax, build tools, underlying principles, component system, CSS solutions, the Hooks family, routing, and state management) with the Vue I'm familiar with, writing down this beginner's perspective on framework comparison and insights.
1. Getting Started and Syntax: Template Directives vs "Everything is JS"
The first chapter of the documentation is about TSX (JSX) syntax. For developers accustomed to Vue's template syntax, this is the first shock.
Business Scenario | Vue (Template Syntax Sugar) | React (TSX / JS Expressions) | Experience |
|---|---|---|---|
Data Interpolation | `{{ message }}` | `{message}` | React uses single curly braces, inside which you can write **any valid JS expression. |
Conditional Rendering | `v-if="flag"` / `v-else` | `flag ? <A /> : <B />` or `flag && <A />` | Vue is directive-oriented; React relies entirely on native JS ternary operators and short-circuit evaluation. |
List Rendering | `v-for="item in list" :key="item.id"` | `list.map(item => <li key={item.id}>{item.name}</li>)` | React has no specific directive; it's just the native array `.map()`. |
Event Binding | `@click="handleClick"` | `onClick={handleClick}` | CamelCase naming, passing function references. |
Class Name Binding | `:class="{ active: isActive }"` | `className={isActive ? 'active' : ''}` | In React, `class` is a JS keyword, so you must use `className`; `for` needs to be written as `htmlFor`. |
Learning Experience:
- Vue feels "structured": Vue provides developers with various directives (v-if, v-for, v-model), the template structure is clear, and HTML looks exactly as it should.
- React feels "free": TSX isn't a template at all; it's essentially a JavaScript syntax extension. You don't need to memorize framework-specific directive syntax; as long as your JS fundamentals are solid, you can freely use if/else, map, filter to assemble UI.
2. Build and Compilation Tools: Babel / SWC vs Vue SFC Compiler
The documentation specifically explains Babel and SWC in the "Tools" section.
- The essence of React transpilation: What we write, <div className="box">Hello</div>, after being transpiled by Babel or SWC, essentially becomes React.createElement('div', { className: 'box' }, 'Hello') (or the newer _jsx('div', ...)).
- Compared to Vue: Vue's core is SFC (Single File Components .vue), parsed by @vitejs/plugin-vue, which compiles <template> into efficient render functions and processes <script> and <style> separately.
Learning Experience:
Only after manually writing Babel/SWC transpilation examples from the documentation did I understand: React components are truly just pure JS functions that return virtual DOM objects, without the strong structural specificity of Vue SFCs.
3. Core Principles: Interruptible Time Slicing vs Fine-Grained Reactivity
The chapters on VDOM, Fiber, Diff, and requestIdleCallback were the most thrilling and mind-bending parts for me.
① Fiber Architecture and Double Buffering
- React's Pain Point and Solution: Early React recursively traversed the VDOM tree; if the component tree was too deep, it would monopolize the main thread, causing frame drops and jank. So React 16 completely refactored to the Fiber architecture, turning the tree structure into alinked list structure, leveraging browser idle scheduling (similar to requestIdleCallback) to achieveinterruptible, resumable asynchronous updates (time slicing). It also uses the "current tree" and "workInProgress tree" double-buffering to improve rendering stability.
- Vue's Solution (Targeted Updates): Vue doesn't need complex time slicing like Fiber at all! Because Vue has Proxy-basedprecise dependency tracking. Vue performs extensive static marking at compile time (PatchFlag, static hoisting), and when data changes, it directly pinpoints the corresponding component or specific DOM node to patch, resulting in minimal update overhead.
② Diff Algorithm Differences
- React Diff: Same-level comparison, only supports one-way rightward movement. If keys match but are positioned earlier, it may cause redundant move operations.
- Vue Diff: Vue 2 usesdual-end Diff(head-head, tail-tail, head-tail cross comparison), while Vue 3 uses afast Diff based on the longest increasing subsequence, which is more extreme in optimizing the number of DOM moves.
4. Component System: The Rigor and Flexibility of Unidirectional Flow
The component section of the documentation covers component communication, controlled components, Portal, Suspense, and HOC (Higher-Order Components).
① Controlled Components vs v-model
This is the most confusing part when first learning React:
- Vue: A single v-model="text" handles two-way binding.
- React: You must explicitly declare it as acontrolled component:
<input value={text} onChange={(e) => setText(e.target.value)} />The data flow is completely unidirectional; state must be passed down from top to bottom, and changes must be communicated through event-triggered updates.
② Slots vs children & Render Props
- Vue: Has an extremely comprehensive slot system (default slots, named slots <template #header>, scoped slots).
- React: Default content is directly obtained via props.children; if you need scoped slot functionality, you can simply pass a function (Render Props pattern: props.render(data)), which is pure JS function parameter passing—simple and direct.
③ Teleport Components and Async Components
- Teleport: React's createPortal(JSX, domNode) corresponds to Vue's <Teleport to="body">.
- Async Loading: React's lazy(() => import(...)) + <Suspense fallback={<Loading />} /> corresponds to Vue's defineAsyncComponent + <Suspense> (但是这部分我在Vue里面没怎么用过...).
④ Higher-Order Components (HOC)
React has a rich HOC culture (functions that take a component and return an enhanced new component), while the Vue community has largely unified around the Composition API after Vue 3, rarely using HOCs. With more Hooks support in React, the use cases for HOCs have also been greatly reduced; according to Xiaoman, they're hardly needed in everyday development.
5. CSS Solutions: Free Exploration vs Out-of-the-Box
In Vue, the most familiar way to write styles is:
<style scoped>
.title { color: red; }
</style>
scoped The attribute automatically adds data-v-xxx attribute selectors to the DOM via PostCSS—clean and easy to use.
In the React documentation, CSS solutions are a "hundred schools of thought":
- CSS Modules: Files are named index.module.css, imported like objects import styles from './index.module.css', and used via className={styles.title}, generating hashed class names for isolation. In the end, it lacks the painless scoped isolation that Vue has.
- CSS-in-JS(like styled-components / emotion): Write styles directly as components. Ant Design uses this approach for its styles.
- Tailwind CSS: Atomic CSS, highly recommended in the documentation. Since it's natural to write in className, it's extremely popular in the React community, and of course, it's also extremely popular in the Vue community. In short, it's just extremely popular.
6. The Core Event: React Hooks Family vs Vue Composition API
After reading the entire documentation, Hooks take up the most space and are the part with the most intense ideological collision with the Vue 3 Composition API.
① useState vs ref / reactive
- Vue: Data is a "mutable reactive proxy."
const count = ref(0)
count.value++ // 直接修改,Proxy 自动捕获并派发更新
- React: Emphasizesimmutable data (Immutable) (feels silly, DX is bad, you have to use a third-party useImmer to improve DX).
const [count, setCount] = useState(0)
setCount(count + 1) // 必须显式调用 setter,不能直接 count = 1
② useEffect vs watch / watchEffect / 生命周期
In Vue, mounting, unmounting, and watching each have their own responsibilities (onMounted, onUnmounted, watch).
In React, the documentation consolidates all "side effects" into useEffect:
- Passing an empty dependency array []: Equivalent to onMounted, and the returned cleanup function is equivalent to onUnmounted.
- Passing dependencies like [count]: Equivalent to watch(count, ...).
- The documentation also introduces the more granular useLayoutEffect(executed synchronously after DOM mutations and before the browser paints, to prevent flicker) and useInsertionEffect(designed specifically for inserting styles in CSS-in-JS).
③ useMemo & useCallback vs computed(The biggest mental burden difference!)
This is what I consider the core difference to adapt to when moving from Vue to React:
- In Vue 3: The component's <script setup> only executes once during initialization.computed automatically collects dependencies and only recalculates when data changes; there's no need to manually manage function references.
- In React: Every time state changes, the entire function component re-executes from top to bottom!
- Ordinary functions inside the component are re-declared with new references on every render, causing unnecessary re-renders of child components when passed down;
- Therefore, you must explicitly use useCallback to cache function references and useMemo to cache computationally intensive results!
Fortunately, in the later Next.js, you can enable the React Compiler to reduce this mental burden; otherwise, it would really kill me 😢
④ The Dual Identity of useRef
In Vue, ref is used both for reactive data and for binding to the DOM.
In React:
- Getting DOM nodes: <div ref={domRef} />;
- Storing mutable data across render cycles: useRef(initialValue) changing .current does not trigger a component re-render, and .currentcan get the bound DOM's value
⑤ Concurrent Feature Hooks (useTransition & useDeferredValue)
The documentation also delves into React 18's concurrent features:
- useTransition: Mark certain non-urgent state updates (like complex list filtering) as low-priority transition tasks to prevent input lag while typing.
- useDeferredValue: Defer the update of a derived value.
This showcases React's formidable capabilities in handling heavy computations and interaction priority scheduling.
7. Routing and Global State Management: React Router and Zustand
① Routing: React Router v7 vs Vue Router
- Vue Router: Centralized route configuration, paired with the built-in <router-view>, and navigation guards (beforeEach) are very intuitive.
- React Router (v7): Has two route behaviors, loader and action, which is a big difference from Vue. You can execute GET requests to fetch data in the route's loader before the page loads, and execute POST form submission logic in the route's action. After submitting form data, returning to the page automatically re-runs the loader to fetch new data. This makes the development experience great. There are also various Hooks like useNavigate(), useParams(), useLoaderData(), useActionData()。
- React Router has many modes, but in practice, using the data router mode, similar to Vue, feels easier to understand.
② State Management: Zustand vs Pinia
The documentation chose the extremely lightweight and elegant Zustand for global state management, rather than the heavyweight traditional Redux:
import { create } from 'zustand'
const useStore = create((set) => ({
bears: 0,
increase: () => set((state) => ({ bears: state.bears + 1 })),
}))
- Compared to Vue's Pinia, the development experience is strikingly similar: both abandon the concept of Mutations, are lightweight, and support direct destructuring of Hooks for use.
- However, Zustand internally still strictly adheres to React's immutable merge philosophy, making it very pure to write.
- Zustand also supports custom middleware and officially recommended third-party middleware like Immer, which is great to use because you don't have to worry about React's silly immutable data principle, even though the underlying principle is still preserved.
Summary: My Learning Reflections
After learning this entire set of React documentation, if I were to summarize the difference between the two in one sentence:
Vue is like a car with an automatic transmission: Reactive auto-tracking, rich template directives, out-of-the-box Scoped CSS. The framework handles the vast majority of optimization details for you, making it smooth to pick up and extremely comfortable to develop with. It's very automatic, and the three core parts (HTML, CSS, JS) aren't separated, making the code beautiful and easy to understand. Beginners can get started quickly, and following the official docs is the right way. The ecosystem is a bit lacking, though.
React is like a purely manual transmission car: No magic, purely driven by authentic JavaScript. Its unidirectional data flow, immutability philosophy, and Fiber architecture are very rigorous, but precisely because of this, many optimizations require you to call Hooks yourself. The three core parts are combined, and the code isn't as pretty. However, React's ecosystem is rich, the community is more enthusiastic, and there are many UI libraries and Hooks libraries. Everyone can tackle React's pain points, making it a thriving ecosystem.
As a frontend learner who has just finished theoretical knowledge and hasn't yet experienced large-scale project development, I don't know if these points are entirely accurate, but this is my personal feeling. I believe learning React is a must nowadays, whether it's for the convenience of React Native's cross-platform capabilities or for reading more excellent React and Next.js projects. React is an essential skill for frontend developers. In the AI era, learning a framework has become easier. You can quickly get answers to things you don't understand from AI. The focus has also shifted from being able to write code to being able to read and understand it, and knowing the logic. The choice of tech stack also seems to lean towards whether AI can write good code for that technology, since, after all, AI is writing the code now.
Comments
No comments yet. Say something?