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++;
}
}
// 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>
);
}
What changed and why
-
File structure – Angular encourages a “feature folder” with separate
.ts,.html, and.scssfiles. React co‑locates JSX, logic, and styling (CSS Modules, styled‑components) in a single file or adjacent files, reducing the number of moving parts. - 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.
-
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. -
Event binding – Angular’s
(click)syntax is declarative and automatically bindsthis. React’sonClickis a prop that receives a function reference; you manage the lexical scope yourself (arrow functions oruseCallback). -
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_batchedUpdatesorstartTransition).
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
-
Set up the toolchain – Install Node ≥ 18, run
npx create-react-app my‑app --template typescript, exploresrc/index.tsxandApp.tsx. -
Learn JSX basics – Convert a simple Angular template (
<p>{{title}}</p>) into JSX (<p>{title}</p>). Practice embedding expressions, ternaries, and array maps. -
State with hooks – Implement a counter, a toggle, and a form using
useState. Compare with Angular’s[(ngModel)]. - Mini project – Build a “Todo list” component that adds, toggles, and removes items. Use local component state only.
Week 2 – Component architecture & routing
- Component composition – Create reusable UI primitives (Button, Card) as separate files. Use props for configuration, mirroring Angular Input bindings.
-
Context API – Build a simple theme provider (
ThemeContext) and consume it in a nested component. Relate this to Angular’sprovidedIn: 'root'services. -
React Router v6 – Install
react-router-dom, define routes (/,/about,/todos/:id). Implement navigation with<Link>and route params withuseParams. -
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
-
Fetching with
fetchanduseEffect– Pull a public JSON placeholder list, handle loading/error states. Compare to Angular’sHttpClient. -
Introduce Redux Toolkit – Install
@reduxjs/toolkitandreact-redux. Create a slice for todos, dispatch actions from components, and select state withuseSelector. - Async thunks – Write an async thunk to load todos from the API, handling pending/fulfilled/rejected cases.
-
Mini project – Refactor the Todo app to store its data in Redux, persisting to
localStoragevia a middleware. Add a “Refresh from server” button.
Week 4 – Advanced patterns & testing
-
Custom hooks – Extract the data‑fetching logic into a
useTodoshook. Compare to Angular services. -
Performance tricks – Use
React.memo,useCallback, anduseMemoto avoid unnecessary renders. Identify a component that re‑renders too often with the React DevTools Profiler. -
Testing with Jest & React Testing Library – Write unit tests for a component (
<TodoItem>), mocking a context provider and asserting DOM output. -
Mini project – Add a “search” feature to the Todo list using a debounced input (
useDebouncehook). 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
- See what already transfers: take the free Angular → React readiness check
- The full Angular → React roadmap, topic by topic
- Related: React developer learning Next.js: what carries over, what's new, 30-day plan
- Related: Migrating Secrets Management: AWS Parameter Store vs Azure Key Vault
Originally published at switchbyskill.com.
Top comments (0)