Dependency Injection is the modal of shared state containers. In very rare cases that people will want to make store run locally. It's worth to say that in some Redux ecosystem store systems, container is overused sometimes. People usually use store to replace component state, a way to separate the business logic from component functionalities. We do not recommend to do so. However, in some cases when the business logic is fat, it's costly to switch between store and component architecture, then having local stores is essential.
Create a Multiple Counter App
For a multiple-counter app, first we need to have an AppRoot which store and render the counters. We will have a global TotalSumStore to manage the total sum:
Sometimes, we may want to connect the local store with the global store. Sometimes, we want to override the global store with the global one. Deviation give you a full control of how stores inheritance should work. When you defined a Deviation as a child of another Deviation, Deviation will automatically inherit the providers from its ancestor via React Context API. So that, you only have to define TotalSumStore at the global Deviation:
Store and component are different, component has state, props and render method. While store has only state. Its props has to be inject via Deviation. It's unpleasant if we want a store act like a component. Actually, store is shared between components. It's trivial that we passing props of an individual component to the store via its props. But there's another way that we can pass the props down to the store. It's via Deviation extra props. For example: