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 a global Context

If you look at the current structure of the routes in your App component, you can imagine this will get messy if you add more Providers and Consumers to your application. State management packages such as Redux tend to have a global state where all of the data for the application is stored. When using Context, it's possible to create a global Context that can be accessed using the useContext Hook. This Hook acts as a Consumer and can retrieve values from the Provider of the Context that was passed to it. Let's refactor the current application to have a global Context:

  1. Start by creating a file called GlobalContext.js in the src/Context directory. This file will import both ListsContextProvider and ItemsContextProvider ...
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