Skip to content

Using MobX #417

Answered by will-stone
will-stone asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, I think I've found the solution by importing and typing the observer function manually. So instead of this:

// Doesn't work and throws an error about missing `react-dom` module
import { observer } from 'mobx-react-lite'

Do this:

import { observer as distObserver } from 'mobx-react-lite/dist/observer'
// @ts-expect-error workaround as mobx-react is expecting react-dom
import { observer as libraryObserver } from 'mobx-react-lite/lib/observer'

type Observer = typeof distObserver

export const observer: Observer = libraryObserver

You can then wrap components in observer as normal.

const App: React.FC<{ game: Game }> = observer(({ game }) => {
  ...
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by will-stone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant