Help us help you! Please choose one:
react-rails, so I've included the stack trace and the exact steps which make it crash.react-rails with another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working.In a pure JS-app I would import PropTypes like so: import React, {PropTypes} from 'react';
As react-rails don't follow that pattern, how do I implement PropTypes in Rails (ES6 style)?
I'm receiving the following error when I try to define proptypes:
Uncaught ReferenceError: PropTypes is not defined
Code:
class MyComponent extends React.Component {
constructor(props) {
super(props);
}
render () {
return (
<div>
Hello World.
</div>
);
}
}
MyComponent.propTypes = {
thingOne: PropTypes.string.isRequired,
thingTwo: PropTypes.string.isRequired
};
This is how I eventually got it to work:
class MyComponent extends React.Component {
}
MyComponent.propTypes = {
someProperty: React.PropTypes.string.isRequired,
someOtherProperty: React.PropTypes.array.isRequired
};
For anyone still arriving here from Google:
In React-Rails 2.4+ we are using React 16 which does not package PropTypes anymore, instead import PropTypes from 'prop-types' and use like so:
MyComponent.propTypes = {
property: PropTypes.string
};
Just so others know, in order to use import or require you'll need to use webpacker instead of the Asset Pipeline, as per the README.
Most helpful comment
For anyone still arriving here from Google:
In React-Rails 2.4+ we are using React 16 which does not package PropTypes anymore, instead
import PropTypes from 'prop-types'and use like so: