Don’t apply inheritance to React components. Composition is simpler and works better:
  • If you’re doing some dirty things you can make use of this function to clone a third object(s) containing all shared stuff (even getters/setters) and assign those clones to your components.
  • Is there a way to efficiently extend components/created classes to other components.
  • For example, I have a component (first component) with a certain HTML structure, but I want to iterate and change it slightly for another component (second component) that shares every other aspect of that first component except for the slightly different render function.
  • But if the components are practically the same as other components abstraction (inheritance) might still be useful.
  • Your Page component will have the common code, while your SomeComponent will differ from page to page.

Read more


dan_abramov

@dan_abramov: “Don’t apply inheritance to React components. Composition is simpler and works better:” open tweet »