DEV Community

Azizi Yazit
Azizi Yazit

Posted on

8 5

Higher Order Component enabled by Ivy

Higher Order Component - HOC

A higher-order component (HOC) is an advanced technique for reusing component logic. Concretely, a higher-order component is a function that takes a component and returns a new component.

Angular HOC

Below is sample HOC withTheme and obviously the code received the component, insert the theme data and return decorated component. Annotated or attached the HOC to the class component is called meta-programming using typescript decorator.

Meta-programming is a technique by which you can modify the code dynamically at runtime.

Alt Text

And below is the HOC usage

Alt Text

Be creative

Ivy is enabler, it enabled HOC and Meta-programming. Be creative, there's so many use-cases can be cater by HOC.

Here is an example of enabling CSS-in-JS using HOC withStyles

Alt Text

And here is some ideas:

withAuth

return auth data if user have been authenticated

withRouter

return a router data

withProvider

return provider reference

Code repository

Check the codes here https://github.com/abumuawiyah/ng-ivy

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay