You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b493fec
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -384,6 +384,7 @@ Hide/Show table of contents
384
384
| 326 | [What is the React Compiler (React Forget)?](#what-is-the-react-compiler-react-forget) |
385
385
| 327 | [What is Streaming SSR and how does React 18+ improve it?](#what-is-streaming-ssr-and-how-does-react-18-improve-it) |
386
386
| 328 | [What is `renderToPipeableStream` and how is it different from renderToString?](#what-is-rendertopipeablestream-and-how-is-it-different-from-rendertostring) |
387
+
| 329 | [What is the difference between HOCs and Hooks?](#what-is-the-difference-between-hocs-and-hooks) |
387
388
388
389
</details>
389
390
@@ -9288,6 +9289,54 @@ Technically it is possible to write nested function components but it is not sug
9288
9289
9289
9290
In practice, prefer `renderToPipeableStream` for React 18+ SSR because it improves perceived performance and works naturally with Suspense-driven progressive loading.
9290
9291
9292
+
**[⬆ Back to Top](#table-of-contents)**
9293
+
9294
+
329. ### What is the difference between HOCs and Hooks?
9295
+
9296
+
Both **Higher-Order Components (HOCs)** and **Hooks** let you reuse logic across components, but they solve that problem in very different ways.
| Pattern | A function that takes a component and returns a new, enhanced component | A function called directly inside a function component |
9301
+
| Component tree | Adds an extra wrapper component, which can lead to "wrapper hell" with multiple HOCs | Adds no extra components to the tree |
9302
+
| Sharing logic | Injects props/behavior into the wrapped component | Shares stateful logic directly via custom hooks (`useX`) |
9303
+
| Prop handling | Can cause prop name collisions when composing multiple HOCs | No prop collisions since state lives inside the component itself |
9304
+
| Debugging | Harder to trace which HOC injected which prop (often needs `displayName`) | Easier to trace; shows up as plain hook calls in React DevTools |
9305
+
| Usage | Works with both class and function components | Can only be used in function components (or other hooks) |
In short, Hooks were introduced to solve the same logic-reuse problem as HOCs (and render props), but without adding extra components to the render tree—avoiding wrapper hell and making the code easier to read, type, and debug. See also [Do Hooks replace render props and higher-order components?](#do-hooks-replace-render-props-and-higher-order-components).
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+
## Expanding the Oxlint configuration
15
+
16
+
If you are developing a production application, we recommend enabling type-aware lint rules by installing `oxlint-tsgolint` and editing `.oxlintrc.json`:
0 commit comments