Reputation: 11
When we call mobx and inject and observe store inside component in following way
**ExampleStore.ts**
import { observable, action } from 'mobx';
export class ExampleStore {
@observable
testData1: any = [];
@observable
testData2: any = [];
}
and
export default inject('exampleStore')(observer((props) => {
// Return component
// Uses testData1 only
}));
Is testData2 injected into React component as well? or only testData1 that is used is injected?
Upvotes: 1
Views: 4002
Reputation: 3009
Both observables are accessible within the component, but the component will only re-render when one of the used observables changes.
Check mobx react integration documentation for more details:
The observer HoC automatically subscribes React components to any observables that are used during rendering.
Upvotes: 1