DailyJS
Published in

DailyJS

Techniques for decomposing React components

Split the render() method

Templatize components by passing React elements as props

Extract common aspects into higher-order components

  1. The component now has an extra concern that obscures its main purpose: displaying a document.
  2. If the component has additional logic in those lifecycle methods, the analytics code also becomes obscured.
  3. The analytics code is not reusable.
  4. Refactoring the component is made harder, as you’d have to work around the analytics code.

Closing thoughts

--

--

JavaScript news and opinion.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store