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

Reusable components

We have seen what the best ways to create components are, and the scenarios where it makes sense to use a local state. We have also seen how we can make our components reusable defining a clear interface with the prop types.

Let's now dive into a real-world example and take a look at how we can transform a non-reusable component into a reusable one with a generic, and cleaner, interface.

Suppose we have a component that loads a collection of posts from an API endpoint, and it shows the list on the screen.

It is a simplified example, but it is useful for understanding the necessary steps we need to take to make components reusable.

The component is defined as follows:

  class PostList extends React.Component

With the constructor ...

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