Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pitfalls.ms #2226

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/best/pitfalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ For more info see [what will MobX react to?](https://mobx.js.org/best/react.html
`@observer` only enhances the component you are decorating, not the components used inside it.
So usually all your components should be decorated. Don't worry, this is not inefficient, in contrast, more `observer` components make rendering more efficient.

### `@inject('store')` before `@observer` will cause MobX to not trigger

The effect with React is that the it will never render on observable changes.

This is wrong
```typescript
@observer
@inject('store')
```
It must be
```typescript
@inject('store')
@observer
```

You'll notice a warning
```
Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'
```


### Don't copy observables properties and store them locally

Observer components only track data that is accessed _during_ the render method. A common mistake is that data plucked of from an observable property and stored will for that reason not be tracked:
Expand Down