React PropTypes.oneIf you specify an enumeration does not work

I have a problem to indicate a property of type "enum" in the reaction. According to the documentation here, the following snippet should work on several components :

position : React.PropTypes.oneOf(['rightTop','rightBottom']) 

But I get the following error

 ERROR in ./app/components/mqttComponents/mqttPresence.jsx Module build failed: SyntaxError:/Users/giuseppe/Projects/sw-director/app/components/mqttComponents/mqttPresence.jsx: Unexpected token (68:36) 66 | propTypes : { 67 | //position: React.PropTypes.string.isRequired, > 68 | position : React.PropTypes.oneOf(['rightTop','rightBottom']), ^ 69 | showMqttClientStatus : React.PropTypes.bool.isRequired, 70 | mqtt: React.PropTypes.object 71 | } 

I don’t understand, what is the mistake? Maybe something has to do with the new ES6 syntax?

+6
source share
1 answer

With ES6 syntax, propTypes in React should be defined as a static property. Therefore, the only difference should be in the propTypes declaration.

 static propTypes = { position : React.PropTypes.oneOf(['rightTop','rightBottom']), showMqttClientStatus : React.PropTypes.bool.isRequired } 
+14
source

All Articles