-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the difference between Decorators and HOCs? #238
Comments
can I work on this issue? |
You can checkout the beautiful documentation here |
can I work on this issue |
Decorators: In frameworks like TypeScript and some versions of JavaScript (like TypeScript or with Babel and plugins), decorators can be used to augment the behavior of classes or methods. For instance, in libraries like MobX or some versions of React, decorators are used to modify the behavior of components or data models. Higher-Order Components (HOCs): For example, an HOC might add authentication checks, data fetching functionality, or additional props to a component without altering its original structure. HOCs are a way to compose components and their behavior flexibly and reusable. Differences: Usage: Decorators are mainly used to augment classes or methods, while HOCs are used in React to enhance components by wrapping them with additional functionality. Implementation: Decorators are part of the language syntax and need proper environment setup (like TypeScript, Babel with relevant plugins) for their usage. At the same time, HOCs are a pure JavaScript pattern that can be used in any JavaScript environment. Both decorators and HOCs serve the purpose of extending or enhancing the functionality of components, but they differ in their implementation, syntax, and usage within the JavaScript ecosystem. |
When I read the implementation in Q35 and Q70, I did not see any difference between decorators and high-order components.
Would you clarify the difference between them and the use case of each one by real example?
The text was updated successfully, but these errors were encountered: