All posts

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 conceptReact equivalentHow it helps you transition
Component‑based UIFunction or class componentsBoth 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 flowprops (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 stateuseState (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 valuesuseMemo or derived values inside renderVue’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 hooksuseEffect (hooks) or class lifecycle methodsVue’s mounted, updated, beforeDestroy correspond to useEffect(() => { … }, []), useEffect(() => { … }), and cleanup functions.
Event handlingv-on → onClick, onChange etc.The pattern “emit an event upward” becomes calling a prop callback (onClick={() => props.onSave()}) or using a context/store.
Scoped CSSCSS Modules / styled‑componentsVue’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 mindsetSeparate .jsx/.tsx and style filesWhile 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 basicsImmutable state updatesVue’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 approachvue-test-utils → @testing-library/reactBoth 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

  1. Template vs JSX – Vue’s <template> uses HTML‑like syntax with directives (@click). React embeds markup directly in JavaScript via JSX, so event handlers become onClick={handler}.
  2. State declaration – Vue’s data returns an object; React uses the useState hook which returns a tuple [value, setter]. The setter must be called to trigger a re‑render.
  3. Methods vs inline functions – Vue groups handlers under methods. In React you can declare functions inside the component or use useCallback for memoization; the example keeps it simple.
  4. Scoped styles – Vue’s <style scoped> automatically scopes selectors. React relies on CSS Modules (ToggleButton.module.css) or CSS‑in‑JS to achieve isolation.
  5. File structure – Vue bundles everything in one .vue file; React typically separates concerns (.jsx for logic/markup, .css for 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

PitfallWhy it happens for Vue devsHow to avoid it
Mutating state directlyVue’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 useEffectVue’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 HTMLVue’s v-html is explicit; in React you must use dangerouslySetInnerHTML.Use dangerouslySetInnerHTML only when necessary and sanitize input.
Using this in function componentsVue’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 drillingVue’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 listsVue 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 automaticallyVue’s <style scoped> does the work. React does not.Use CSS Modules, styled‑components, or BEM naming to avoid collisions.
Mixing default and named importsVue’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

  1. Set up the toolchain – Install Node ≥ 18, run npx create-react-app my-app (or Vite with npm create vite@latest). Commit the scaffold to Git.
  2. Learn JSX basics – Convert a simple Vue template (e.g., a list rendering) to JSX, paying attention to {} interpolation and className.
  3. State with useState – Re‑implement a Vue component that toggles visibility using useState.
  4. Mini project: Build a Todo List that adds, toggles, and deletes items. Use only functional components and useState.

Week 2 – Effects, Context, and Routing

  1. Side effects – Replace a Vue mounted API call with useEffect(() => { … }, []). Experiment with cleanup functions.
  2. React Router – Install react-router-dom, create a two‑page app (Home / About). Compare Vue Router’s <router-link> to <Link> component.
  3. Context API – Move the Todo List’s state to a Context provider and consume it in a child component. Observe re‑renders.
  4. Mini project: Extend the Todo app with persistent storage using localStorage inside useEffect. Add a settings page reachable via routing.

Week 3 – Advanced Patterns

  1. Custom hooks – Extract the Todo logic into a useTodos hook. Compare to Vue composables.
  2. Performance – Use React.memo and useCallback to prevent unnecessary renders in a list with many items.
  3. Styling – Switch from global CSS to CSS Modules or styled‑components; verify that styles are scoped.
  4. 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

  1. State management – Explore a lightweight store like Zustand or Jotai; compare to Vuex/Pinia. Implement a global counter.
  2. Testing – Write unit tests with @testing-library/react for the Dashboard components; add a few integration tests with Cypress.
  3. 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.
  4. 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