7 min read
Vue developer learning React: what carries over, what's new, 30-day plan
Practical guide for Vue developers transitioning to React, covering transferable concepts, new patterns, pitfalls, a 30‑day roadmap, and quick FAQs.
What carries over
| Vue concept | React equivalent | How it helps you transition |
|---|---|---|
| Component‑based UI | Function or class components | Both frameworks break the UI into reusable, isolated units. Your habit of thinking in “components that own their template and logic” maps directly to React’s JSX‑based components. |
| Props for data flow | props (read‑only) | In Vue you pass data with :prop="value"; in React you use <MyComp value={value} />. The unidirectional flow is the same mental model. |
| Local state | useState (hooks) or this.state (class) | Vue’s data object becomes component state. The rule “state is private to the component unless lifted” stays unchanged. |
| Computed / derived values | useMemo or derived values inside render | Vue’s computed properties are just memoized functions. In React you can achieve the same with useMemo(() => …, [deps]) or by computing directly in the render function when cheap. |
| Lifecycle hooks | useEffect (hooks) or class lifecycle methods | Vue’s mounted, updated, beforeDestroy correspond to useEffect(() => { … }, []), useEffect(() => { … }), and cleanup functions. |
| Event handling | v-on → onClick, onChange etc. | The pattern “emit an event upward” becomes calling a prop callback (onClick={() => props.onSave()}) or using a context/store. |
| Scoped CSS | CSS Modules / styled‑components | Vue’s <style scoped> isolates styles; in React you can use CSS Modules (import styles from './Comp.module.css') or CSS‑in‑JS libraries to get the same encapsulation. |
| Single‑file component mindset | Separate .jsx/.tsx and style files | While Vue bundles template, script, and style, the idea of co‑locating a component’s logic, markup, and styles persists; you’ll just split them into files that are imported together. |
| Reactivity basics | Immutable state updates | Vue’s reactivity system automatically tracks dependencies; React requires you to treat state as immutable and call the setter to trigger a re‑render. The conceptual goal—UI reflects state—remains identical. |
| Testing approach | vue-test-utils → @testing-library/react | Both encourage shallow rendering and interaction testing. Your test‑first mindset transfers without friction. |
What's new
Side‑by‑side example: a toggle button
Vue (single‑file component)
<template>
<button @click="toggle">{{ isOn ? 'ON' : 'OFF' }}</button>
</template>
<script>
export default {
data() {
return { isOn: false }
},
methods: {
toggle() {
this.isOn = !this.isOn
}
}
}
</script>
<style scoped>
button { padding: 0.5rem 1rem; }
</style>
React (function component with hooks)
import { useState } from 'react';
import './ToggleButton.css'; // CSS Modules or plain CSS
export default function ToggleButton() {
const [isOn, setIsOn] = useState(false);
const toggle = () => setIsOn(prev => !prev);
return (
<button onClick={toggle}>
{isOn ? 'ON' : 'OFF'}
</button>
);
}
What changed and why
- Template vs JSX – Vue’s
<template>uses HTML‑like syntax with directives (@click). React embeds markup directly in JavaScript via JSX, so event handlers becomeonClick={handler}. - State declaration – Vue’s
datareturns an object; React uses theuseStatehook which returns a tuple[value, setter]. The setter must be called to trigger a re‑render. - Methods vs inline functions – Vue groups handlers under
methods. In React you can declare functions inside the component or useuseCallbackfor memoization; the example keeps it simple. - Scoped styles – Vue’s
<style scoped>automatically scopes selectors. React relies on CSS Modules (ToggleButton.module.css) or CSS‑in‑JS to achieve isolation. - File structure – Vue bundles everything in one
.vuefile; React typically separates concerns (.jsxfor logic/markup,.cssfor styles).
Other new concepts:
- Hooks – React’s functional paradigm revolves around hooks (
useEffect,useContext,useReducer). They replace Vue’s options API and give you fine‑grained control over side effects. - JSX is JavaScript – You can use any JS expression inside
{}; no need for Vue’s template interpolation rules. - Explicit imports – Every component, hook, and utility must be imported; there is no global registration like Vue’s
app.component. - Strict immutability – Updating nested state requires shallow copies (
setState(prev => ({ ...prev, nested: newVal }))). Vue’s proxy‑based reactivity hides this, but React expects you to manage it.
Common pitfalls
| Pitfall | Why it happens for Vue devs | How to avoid it |
|---|---|---|
| Mutating state directly | Vue’s proxies let you write this.foo = … anywhere. In React you must call the state setter. | Always use the setter (setFoo(newVal)). For objects/arrays, spread‑copy before updating. |
Forgetting dependency arrays in useEffect | Vue’s watch runs only when watched sources change. In React an empty useEffect runs once, but omitting the array makes it run on every render. | Explicitly pass [] for “run once” or [dep1, dep2] for specific dependencies. |
| Assuming JSX auto‑escapes HTML | Vue’s v-html is explicit; in React you must use dangerouslySetInnerHTML. | Use dangerouslySetInnerHTML only when necessary and sanitize input. |
Using this in function components | Vue’s options API relies on this. React function components have no this. | Keep all logic inside the function scope or use hooks; never reference this. |
| Over‑using context for simple prop drilling | Vue’s provide/inject is often used for deep trees. React’s Context has a higher render cost if misused. | Reserve Context for truly global data; otherwise lift state up and pass props. |
| Neglecting key props in lists | Vue warns about missing key. React will silently reuse DOM nodes, causing bugs. | Always provide a stable key (key={item.id}) when rendering arrays. |
| Assuming CSS is scoped automatically | Vue’s <style scoped> does the work. React does not. | Use CSS Modules, styled‑components, or BEM naming to avoid collisions. |
| Mixing default and named imports | Vue’s default export (export default) is common. React components are usually default‑exported, but utilities are named. | Follow the library’s export style; import React, { useState } from 'react'. |
Your 30‑day plan
Week 1 – Foundations
- Set up the toolchain – Install Node ≥ 18, run
npx create-react-app my-app(or Vite withnpm create vite@latest). Commit the scaffold to Git. - Learn JSX basics – Convert a simple Vue template (e.g., a list rendering) to JSX, paying attention to
{}interpolation andclassName. - State with
useState– Re‑implement a Vue component that toggles visibility usinguseState. - Mini project: Build a Todo List that adds, toggles, and deletes items. Use only functional components and
useState.
Week 2 – Effects, Context, and Routing
- Side effects – Replace a Vue
mountedAPI call withuseEffect(() => { … }, []). Experiment with cleanup functions. - React Router – Install
react-router-dom, create a two‑page app (Home / About). Compare Vue Router’s<router-link>to<Link>component. - Context API – Move the Todo List’s state to a Context provider and consume it in a child component. Observe re‑renders.
- Mini project: Extend the Todo app with persistent storage using
localStorageinsideuseEffect. Add a settings page reachable via routing.
Week 3 – Advanced Patterns
- Custom hooks – Extract the Todo logic into a
useTodoshook. Compare to Vue composables. - Performance – Use
React.memoanduseCallbackto prevent unnecessary renders in a list with many items. - Styling – Switch from global CSS to CSS Modules or styled‑components; verify that styles are scoped.
- Mini project: Create a Dashboard with a chart (e.g., using
recharts) and a data table. Use custom hooks for data fetching, memoization for expensive calculations, and Context for theme toggling.
Week 4 – Ecosystem & Production
- State management – Explore a lightweight store like Zustand or Jotai; compare to Vuex/Pinia. Implement a global counter.
- Testing – Write unit tests with @testing-library/react for the Dashboard components; add a few integration tests with Cypress.
- Build & Deploy – Run
npm run build, serve the static files locally, then deploy to a free static host (e.g., Netlify). Verify source maps and environment variables. - Mini project: Polish the Dashboard, add error boundaries, and write a short README that explains the architecture.
By the end of the month you’ll have touched every core React concept, built three progressively larger apps, and exercised the tooling that surrounds a production React codebase.
FAQ
How different is the learning curve compared to moving from Vue 2 to Vue 3?
The shift to React introduces a new syntax (JSX) and a hook‑centric mental model, which is steeper than Vue’s optional Composition API but still manageable with daily practice.
Do I need to learn TypeScript for React?
Not immediately; React works perfectly with plain JavaScript. However, most modern React codebases adopt TypeScript, so consider adding it after you’re comfortable with the core concepts.
Should I keep using Vue‑style single‑file components?
React does not have an exact equivalent, but you can approximate the experience with tools like Vite and MDX. Most teams prefer separate .jsx/.tsx and .css files for clarity.
Is React’s Context a replacement for Vuex/Pinia?
Context is good for low‑frequency global data (theme, locale). For complex state with actions, mutations, and devtools, a dedicated store (Zustand, Jotai, Redux) is more appropriate.
Keep going
#vue #react #learning #guide