Skip to Main Content
React Design Patterns and Best Practices - Second Edition
book

React Design Patterns and Best Practices - Second Edition

by Carlos Santana Roldán
March 2019
Intermediate to advanced content levelIntermediate to advanced
350 pages
7h 28m
English
Packt Publishing
Content preview from React Design Patterns and Best Practices - Second Edition

Higher order components

In the previous section, we saw how mixins are useful for sharing functionalities between components and the problems that they bring to our applications.

In the Functional Programming section of Chapter 2, Clean Up Your Code, we mentioned the concept of higher order functions (HoFs), which are functions that, given a function, enhance it with some extra behaviors, returning a new one.

Let's see if we can apply the same concept to React components and achieve our goal of sharing functionalities between components while avoiding the downsides of mixins.

When we apply the idea of HoFs to components, we call this higher order components (HoCs) for brevity.

First of all, let's see what an HoC looks like:

  const HoC = Component ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React 17 Design Patterns and Best Practices - Third Edition

React 17 Design Patterns and Best Practices - Third Edition

Carlos Santana Roldán

Publisher Resources

ISBN: 9781789530179Supplemental Content