mobx icon indicating copy to clipboard operation
mobx copied to clipboard

Store update not invoking the render function when used with react-jss

Open zeekayzeekay opened this issue 8 years ago • 1 comments

I am using mobx-react, in conjunction with the react-jss library for styling.

The issue that I am facing is that the store updates are not causing the related components to re-render. The exact scenario can be replicated here https://codesandbox.io/s/l3r0qmq3zl

Observations -

  • I am injecting the styles first using the injectSheet method of react-jss, followed by the mobx store. In this manner the store is available as props to the style rules ( which is needed to update the style dynamically on prop updates), but apparently this is also causing the components to not re-render on store updates.
  • If the mobx store is injected first, then there is no issue with rendering on updates, but that would cause the store to not be available in the props which is used by the styles.
  • Also, I have tried using both the injecting functions of mobx and react-jss as decorators instead of as functions, it causes the same behavior.

Mobx version used - 3.5.1 Mobx-react version used - 4.4.2 React-jss version used - 8.4.0 Browser - Electron 1.8.2

I would like to know that if there's something at my end that I can do to work around this issue, or if am doing something wrong here itself?

zeekayzeekay avatar Apr 07 '18 13:04 zeekayzeekay

I was using the observer function at the wrong step. It should have been like this const InjectedTimerView = inject("store")(injectSheet(styles)(observer(TimerView)))

zeekayzeekay avatar Apr 07 '18 14:04 zeekayzeekay