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

Prop validation throws a warning still an issue. Related to closed ticket #70 #142

Closed
mromanoff opened this issue Oct 28, 2016 · 11 comments
Closed

Comments

@mromanoff
Copy link

Related to: Prop validation throws a warning when used on a decorated component expecting store #70

@mweststrate i followed your last post on this topic. and still getting warning.
Mobx Injector: you are trying to attach propTypes to HOC instead of Actions. Use wrappedComponent property.

here is my component:

@inject('store') @observer
export default class Actions extends Component {
    render() {
        return <div>abc</div>;
    }
}

Actions.wrappedComponent.propTypes = {
  store: PropTypes.object.isRequired
};

am i missing something?
btw I'm using Babel

@SagiMedina
Copy link

@mromanoff did you find any solution to this warning?
@mweststrate Any thoughts?

@mromanoff
Copy link
Author

@SagiMedina sorry but i did not find any solution. for now I ignore this message.

@mweststrate
Copy link
Member

@mromanoff @SagiMedina just tried to reproduce this issue, but it worked for me without warnings. Could you setup a small reproduction? Are you using the latest mobx-react version?

@mromanoff
Copy link
Author

mromanoff commented Nov 1, 2016

@mweststrate thank you for quick response. Due complexity of this project I'm working on and running on local environment only. I can send you link to public repo if this helps.
API: /~https://github.com/mromanoff/therapy-match-api
FE: /~https://github.com/mromanoff/therapy-match
Let me know if you can quick spot the issue. If not then I need to deploy this project on Heroku or Digital Ocean.

Currently I have 4 warning messages:

Mobx Injector: you are trying to attach propTypes to HOC instead of Actions. Use `wrappedComponent` property.
Mobx Injector: you are trying to attach propTypes to HOC instead of Search. Use `wrappedComponent` property.
Mobx Injector: you are trying to attach propTypes to HOC instead of Provider. Use `wrappedComponent` property
Mobx Injector: you are trying to attach propTypes to HOC instead of Success. Use `wrappedComponent` property.

i'm using mobx-react@3.5.8

@SagiMedina
Copy link

@mweststrate Please take a look here, /~https://github.com/SagiMedina/system_dashboard
I have 6 warning messages, one for every store injection.

@SagiMedina
Copy link

SagiMedina commented Nov 9, 2016

Never mind, adding the wrappedComponent to the props validation fixed it.
SagiMedina/system_dashboard@1e0bcf6 @mromanoff

@mweststrate
Copy link
Member

@mromanoff you still seem to attach the propTypes to Search, so the warning is correct? /~https://github.com/therapymatch/therapymatch-fe/blob/e1e90d6b48b1fd80fb9fd6d6e3d330d7057ea2d6/src/components/Search/Search.js#L60

@mweststrate
Copy link
Member

That being said, mobx-react@4 will probably redirect the property, instead of giving a warning, which is more convenient to work with:)

mweststrate added a commit that referenced this issue Nov 9, 2016
This change forward writes (but not reads!) of `propTypes` and `defaultProps` on an inject based HoC to the wrapped component, so that propTypes and defaultProps can be defined in a straight forward way.
@mromanoff
Copy link
Author

mromanoff commented Nov 10, 2016

@mweststrate oh... my assumption was that I need to use .wrappedComponent only for "inject", "observer" store props but not for the other props. route props etc.

I had before:

Search.propTypes = {
  params: PropTypes.object.isRequired
};
Search.wrappedComponent.propTypes = {
  providersStore: PropTypes.object.isRequired
};

I have now:

Search.wrappedComponent.propTypes = {
  params: PropTypes.object.isRequired,
  providersStore: PropTypes.object.isRequired
};

the warning message gone.
thank you for your help and spotting the issues i had.

@mweststrate
Copy link
Member

I've made the distinction between HoC's and non-HoC's more clear in mobx-react@4.0.0-rc.1 and removed the warnings. It is now allowed to define the propTypes on the HoC again. But note that you cannot check for the presence of your stores there, for that you will still need .wrappedComponent.

@mweststrate
Copy link
Member

4.0.0 has been released :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants