Skip to Main Content
React Projects
book

React Projects

by Roy Derks
December 2019
Intermediate to advanced content levelIntermediate to advanced
474 pages
10h 3m
English
Packt Publishing
Content preview from React Projects

Creating HOC

As we mentioned previously, HOCs focus on reusing components. Therefore, it can best be described as follows:

"A HOC is a function that takes a component and returns a new component."

To explain what this means in practice, let's create an example. Our project has a Board component, which fetches and renders all the lanes. There is logic in this component in the form of a constructor, a componentDidMount, and information about how each Lane component is being rendered. How would we handle a situation where we just want to show a board without lanes, but only tickets? Do we just send different props to the Board component? Sure, that's possible, but, in React, that's what HOCs are used for.

A Board component without lanes wouldn't ...

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 Projects - Second Edition

React Projects - Second Edition

Roy Derks
Test-Driven React

Test-Driven React

Trevor Burnham

Publisher Resources

ISBN: 9781789954937Supplemental Content