Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

inject function introduces conflict with new React static context #612

Closed
zisiszikos opened this issue Nov 23, 2018 · 9 comments
Closed

Comments

@zisiszikos
Copy link

I'm trying to use mobx-react inject function along with the new static context of React, and I'm getting this error:

Warning: inject-MainCompClass declares both contextTypes and contextType static properties. The legacy contextTypes property will be ignored.

Check the console at this example.

I guess that inject uses the old React context style, and React decides to use only the new style used by the component. This has as a result, the mobx store to be undefined.

Versions:
react: 16.6.3
mobx: 5.6.0
mobx-react: 5.4.2
@mweststrate
Copy link
Member

mweststrate commented Nov 27, 2018 via email

@titouancreach
Copy link

titouancreach commented Nov 28, 2018

I think @zisiszikos is right. static contextType is a new React feature that we cannot use because of mobx-react. I've a different error but I think this is the same bug behind

react-dom.development.js:506 Warning: inject-Header-with-xxxxxxx declares both contextTypes and contextType static properties. The legacy contextTypes property will be ignored.
index.module.js:645 Uncaught Error: MobX injector: Store 'xxxxxxx' is not available! Make sure it is provided by some Provider

In my case, that make the mobx contextTypes to be ignored

To reproduce, just try to play arround with the new feature static contextType

@ntucker
Copy link

ntucker commented Dec 6, 2018

This library should use https://github.com/jamiebuilds/create-react-context so it can work with next react context.

@ntucker
Copy link

ntucker commented Dec 7, 2018

needs hoist-non-react-statics upgrade

@ntucker
Copy link

ntucker commented Dec 12, 2018

@zisiszikos try adding

"resolutions": {
    "hoist-non-react-statics": "3.2.1"
  }

to your package.json.

This should force this library to use the latest hoist-non-react-statics since they haven't upgraded.

@ntucker
Copy link

ntucker commented Dec 12, 2018

apparently observer just breaks classes that use static contextType unequivocally. I'm going to introduce another wrapper component just to solve that issue.

@mweststrate
Copy link
Member

Reproduced, thanks for reporting. Will release a fix soon

@mweststrate
Copy link
Member

Fix has been released as 5.4.3

@zisiszikos
Copy link
Author

Perfect! I confirm that is working now.
Check the updated example.

@github-actions github-actions bot mentioned this issue Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants