Today I learned something at work. I am new to MobX and I had to make changes to a React + Typescript + MobX project. I noticed the props of some React components were marked as optional, and I was told it was because of how the dependency injection worked.
When injecting MobX stores into React components in Typescript, the recommended approach in MobX docs involves declaring optional props (?
). This results in having to perform null checks when accessing an injected store, and MobX recommendeds using the non-null assertion operator (!
).
interface BananaProps {