Dev Summit '24

Dependency Injection with React Context

About this presentation

Dependency injection is a common software pattern, with clear benefits, including easier testing, and better reusability of code. While there are React dependency-injection libraries available, React doesn't provide a native implementation of this pattern. It does, however, provide useContext, which can be used to gain many of the benefits of dependency injection. Today, we're going to take a look at why you might want to use dependency injection, how you can go about doing it with useContext, and what the pros and cons are of this approach vs using a library.