Monday, September 26, 2022
HomeSoftware EngineeringHow To Reuse React Parts | by Sabesan Sathananthan | Codezillas

How To Reuse React Parts | by Sabesan Sathananthan | Codezillas

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

Photograph by Vlada Karpovich from Pexels
  • There may be an implicit dependency between the element and the mixin (Mixin typically is determined by the precise methodology of the element, however the dependency isn’t identified when the element is outlined).
  • There could also be conflicts between a number of mixin (akin to defining the identical state subject).
  • Mixin tends so as to add extra states, which reduces the predictability of the appliance and results in a pointy enhance 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 mandatory to completely perceive all of the extension behaviors that depend on mixin and their mutual affect.
  • The strategy and state subject of the element itself is afraid to be simply deleted as a result of it’s tough to find out whether or not mixin is determined by it.
  • Mixin can also be tough to take care of, as a result of Mixin logic will finally be flattened and merged collectively, and it’s tough to determine the enter and output of a Mixin.


  • Scalability restriction: HOC can’t utterly substitute Mixin. In some situations, Mixin can however HOC can’t. For instance, PureRenderMixin, as a result of HOC can’t entry the State of subcomponents from the skin, and on the similar time filter out pointless updates by way of shouldComponentUpdate. Subsequently, React After supporting ES6Class, React.PureComponent is offered to resolve this downside.
  • Ref switch downside: Ref is minimize off. The switch downside of Ref is kind of annoying below the layers of packaging. The operate Ref can alleviate a part of it (permitting HOC to study node creation and destruction), so the React.forwardRef API API was launched later.
  • WrapperHell: HOC is flooded, and WrapperHell seems (there is no such thing as a downside that can not be solved by one layer, if there may be, then two layers). Multi-layer abstraction additionally will increase complexity and price of understanding. That is essentially the most important defect. In HOC mode There isn’t any 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