Monday, November 28, 2022
HomeSoftware EngineeringHow To Reuse React Elements | by Sabesan Sathananthan | Codezillas

How To Reuse React Elements | by Sabesan Sathananthan | Codezillas

Mixins, HOC, render props, and Hooks are 4 methods to reuse parts

Photograph by Vlada Karpovich from Pexels
  • There’s an implicit dependency between the part and the mixin (Mixin usually relies on the particular technique of the part, however the dependency isn’t recognized when the part is outlined).
  • There could also be conflicts between a number of mixin (reminiscent of defining the identical state discipline).
  • Mixin tends so as to add extra states, which reduces the predictability of the applying and results in a pointy improve in complexity.
  • Implicit dependencies result in opaque dependencies, and upkeep prices and understanding prices are rising quickly.
  • It’s tough to rapidly perceive the conduct of parts, and it’s obligatory to totally perceive all of the extension behaviors that depend on mixin and their mutual affect.
  • The strategy and state discipline of the part itself is afraid to be simply deleted as a result of it’s tough to find out whether or not mixin relies on it.
  • Mixin can also be tough to keep up, as a result of Mixin logic will ultimately be flattened and merged collectively, and it’s tough to determine the enter and output of a Mixin.


  • Scalability restriction: HOC can not utterly exchange Mixin. In some eventualities, Mixin can however HOC can not. For instance, PureRenderMixin, as a result of HOC can not entry the State of subcomponents from the surface, and on the similar time filter out pointless updates via shouldComponentUpdate. Due to this fact, React After supporting ES6Class, React.PureComponent is offered to unravel this downside.
  • Ref switch downside: Ref is minimize off. The switch downside of Ref is kind of annoying beneath the layers of packaging. The perform Ref can alleviate a part of it (permitting HOC to find out about node creation and destruction), so the React.forwardRef API API was launched later.
  • WrapperHell: HOC is flooded, and WrapperHell seems (there isn’t any downside that can not be solved by one layer, if there may be, then two layers). Multi-layer abstraction additionally will increase complexity and value of understanding. That is essentially the most essential defect. In HOC mode There isn’t a good resolution.


  • Property agent Props Proxy.
  • Reverse inheritance Inheritance Inversion.

Property Agent

Reverse inheritance


const NavbarWithRouter = withRouter(Navbar);
const CommentWithRelay = Relay.createContainer(Remark, config);


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments