DEV Community

Switch by Skill
Switch by Skill

Posted on Originally published at switchbyskill.com

Angular developer learning React: what carries over, what's new, 30-day plan

What carries over

Angular concept React equivalent / relevance
Component‑based architecture Both frameworks revolve around reusable components. In Angular you declare a component with @Component, in React you write a function or class that returns JSX. The mental model of “a UI piece with its own template and logic” stays the same.
Dependency injection (DI) basics Angular’s built‑in DI container is more opinionated, but the idea of providing a service instance to a component persists. In React you achieve the same with the Context API or custom hooks (useContext). The pattern of “pulling a dependency from a shared source instead of new‑ing it” is unchanged.
Unidirectional data flow Angular’s @Input / @Output pattern maps to React’s props‑down, events‑up model. You still pass data from parent to child via props and notify the parent via callbacks (onClick, custom handlers).
Lifecycle awareness Angular’s ngOnInit, ngOnChanges, ngOnDestroy have React counterparts in useEffect (with appropriate dependency arrays) and cleanup functions. The need to run side‑effects at the right moment is identical.
Template syntax for binding Angular’s interpolation {{value}} and property binding [src]="url" become JSX expressions {value} and attribute values {url}. The underlying principle—embedding JavaScript expressions in markup—remains.
Routing concepts Angular Router’s route definitions (path, component) map to React Router’s <Route path="" element={...} />. Guarding routes, lazy loading modules, and param extraction are all present, just with different APIs.
Testing mindset Unit testing components with Jasmine/Karma translates to testing React components with Jest and React Testing Library. The focus on isolated rendering, mocking services, and asserting DOM output does not change.
State management patterns NgRx’s store, actions, reducers, selectors are conceptually identical to Redux (or Redux Toolkit) in React. If you already use NgRx, the mental model of a single source of truth and immutable updates will feel familiar.

What's new

Below is a tiny “click counter” implemented in both frameworks. The Angular version uses a component class, template, and two‑way binding. The React version uses a functional component with hooks.

// Angular (TypeScript)
import { Component } from '@angular/core';

@Component({
  selector: 'app-counter',
  template: `
    <button (click)="increment()">Clicked {{ count }} times</button>
  `
})
export class CounterComponent {
  count = 0;
  increment() {
    this.count++;
  }
}
Enter fullscreen mode Exit fullscreen mode
// React (JavaScript)
import { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);
  const increment = () => setCount(c => c + 1);

  return (
    <button onClick={increment}>
      Clicked {count} times
    </button>
  );
}
Enter fullscreen mode Exit fullscreen mode

What changed and why

  1. File structure – Angular encourages a “feature folder” with separate .ts, .html, and .scss files. React co‑locates JSX, logic, and styling (CSS Modules, styled‑components) in a single file or adjacent files, reducing the number of moving parts.
  2. Templates vs JSX – Angular’s HTML template is parsed by the Angular compiler; you write plain HTML with Angular directives. React’s JSX is JavaScript syntax sugar; every expression is compiled by Babel/TSX, giving you full JavaScript power inside markup.
  3. State handling – Angular’s component class fields (count) are mutable; change detection runs automatically. In React you must treat state as immutable and call the setter (setCount) to trigger a re‑render. This explicitness avoids hidden side‑effects.
  4. Event binding – Angular’s (click) syntax is declarative and automatically binds this. React’s onClick is a prop that receives a function reference; you manage the lexical scope yourself (arrow functions or useCallback).
  5. Change detection – Angular runs a zone‑based change detection cycle after every async event. React uses a virtual DOM diff on each state update, which can be more predictable but requires you to batch updates when needed (e.g., unstable_batchedUpdates or startTransition).

Common pitfalls

Pitfall Why it happens for Angular vets How to avoid it
Mutating state directly In Angular you can assign this.someObj.prop = 5 and the framework picks it up. In React you must create a new object (setObj(prev => ({...prev, prop: 5}))). Always treat props and state as immutable. Use spread syntax or utility libraries (immer) to produce new objects.
Forgetting the dependency array in useEffect Angular’s ngOnInit runs once, and ngOnChanges runs on input changes automatically. In React, useEffect runs after every render unless you pass a dependency array. Add an empty array [] for “run once” effects, or list specific variables to re‑run on change.
Using this in functional components Angular classes rely on this for services and properties. React functional components have no this. Switch to hooks (useState, useRef, useContext). If you need a class component, remember that this refers to the component instance, not a DI container.
Assuming Angular’s DI will work in React Angular’s @Injectable services are provided by the injector tree. React has no built‑in injector. Use Context to provide global services, or keep a separate service layer (plain classes) and import them where needed.
Overusing JSX for complex logic Angular templates discourage heavy logic; you move it to the component class. JSX can embed any JS, tempting you to write loops or conditionals directly in markup. Keep JSX declarative; extract complex calculations into helper functions or custom hooks.
Neglecting key props in lists Angular’s *ngFor tracks by identity automatically. React requires a key prop for each list item to preserve identity. Always provide a stable key (id or index if truly static).

Your 30‑day plan

Week 1 – Foundations

  1. Set up the toolchain – Install Node ≥ 18, run npx create-react-app my‑app --template typescript, explore src/index.tsx and App.tsx.
  2. Learn JSX basics – Convert a simple Angular template (<p>{{title}}</p>) into JSX (<p>{title}</p>). Practice embedding expressions, ternaries, and array maps.
  3. State with hooks – Implement a counter, a toggle, and a form using useState. Compare with Angular’s [(ngModel)].
  4. Mini project – Build a “Todo list” component that adds, toggles, and removes items. Use local component state only.

Week 2 – Component architecture & routing

  1. Component composition – Create reusable UI primitives (Button, Card) as separate files. Use props for configuration, mirroring Angular Input bindings.
  2. Context API – Build a simple theme provider (ThemeContext) and consume it in a nested component. Relate this to Angular’s providedIn: 'root' services.
  3. React Router v6 – Install react-router-dom, define routes (/, /about, /todos/:id). Implement navigation with <Link> and route params with useParams.
  4. Mini project – Extend the Todo app into a multi‑page app: a list view (/todos) and a detail view (/todos/:id). Add a navigation bar.

Week 3 – Data fetching & state management

  1. Fetching with fetch and useEffect – Pull a public JSON placeholder list, handle loading/error states. Compare to Angular’s HttpClient.
  2. Introduce Redux Toolkit – Install @reduxjs/toolkit and react-redux. Create a slice for todos, dispatch actions from components, and select state with useSelector.
  3. Async thunks – Write an async thunk to load todos from the API, handling pending/fulfilled/rejected cases.
  4. Mini project – Refactor the Todo app to store its data in Redux, persisting to localStorage via a middleware. Add a “Refresh from server” button.

Week 4 – Advanced patterns & testing

  1. Custom hooks – Extract the data‑fetching logic into a useTodos hook. Compare to Angular services.
  2. Performance tricks – Use React.memo, useCallback, and useMemo to avoid unnecessary renders. Identify a component that re‑renders too often with the React DevTools Profiler.
  3. Testing with Jest & React Testing Library – Write unit tests for a component (<TodoItem>), mocking a context provider and asserting DOM output.
  4. Mini project – Add a “search” feature to the Todo list using a debounced input (useDebounce hook). Write a test that verifies the filtered results.

At the end of the month you should have a small but complete React codebase that mirrors the structure of a typical Angular app, but uses idiomatic React patterns.

FAQ

How do I replace Angular services in React?

Use the Context API to provide a singleton-like object, or simply export a class instance and import it where needed. For reactive streams, consider RxJS directly or useObservable hooks.

Do I still need TypeScript?

Yes. Create‑React‑App’s TypeScript template gives you the same static typing benefits you enjoy in Angular. All component props, state, and context values should be typed.

Should I learn Redux before React Router?

No. Both are independent libraries. Start with routing to get comfortable navigating between pages, then add Redux (or Redux Toolkit) when you need shared state beyond simple prop drilling.

Is there an equivalent to Angular’s ngIf and ngFor?

Yes. In JSX you use JavaScript expressions: {condition && <Component/>} for ngIf, and {items.map(item => <Component key={item.id} {...item} />)} for ngFor. The logic lives in JavaScript rather than a template syntax.

Keep going

Originally published at switchbyskill.com.

Top comments (0)