This repository was archived by the owner on Dec 31, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 346
Mobx-React does not work with React.CreateContext #471
Copy link
Copy link
Closed
Description
Versions
Newest versions as of May 2018
mobx: 4.2.1
mobx-react: 5.1.2
react: 16.3.2
react-dom: 16.3.2
Bug
It seems like it is not possible to create an observing context consumer.
// A simple store which counts up the count value:
class CounterStore {
@observable count: number = 0;
}
const counterStore = new CounterStore();
setInterval(() => counterStore.count ++, 1000);
// A simple context for the store
const Context = React.createContext<CounterStore>(null);
Expected behaviour
All context.consumers which rely on an observed value should rerender once an observed value changes.
Actual behaviour
The following screenshot contains two components which rely on the same observable value.
The first component does not access the observed value the second one does.
As you can see the first component does not rerender.
Demo
The following demos show two scenarios for the same problem:
ReactContext which holds a mobx store
https://stackblitz.com/edit/react-ts-q5ktj1?file=index.tsx
ReactContext which does not hold a mobx store
https://stackblitz.com/edit/react-ts-rjk13r?file=index.tsx
arel
Metadata
Metadata
Assignees
Labels
No labels
