Building Custom React HooksEntry 5 of 5
Summary
| Concept | React | Angular |
|---|---|---|
| Reusable stateful logic | Custom hook (useX) | Function with signals (injectX) or service |
| Naming rule | Must start with use | None (convention: injectX) |
| Where it can be called | Components and hooks, top level | Injection context if it uses inject() |
| Built-in data fetching | — (build useFetch, or use a library) | resource() / httpResource() |
| Cleanup | Effect cleanup | DestroyRef |
| State scope | Per calling component | Per call (function) or per injector (service) |
| Share state | Context / Redux Toolkit | Service |
A custom hook is React's way to reuse stateful logic without sharing state. Angular splits the same idea in two: functions for per-component logic and services for shared state.