Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 641 Bytes

File metadata and controls

42 lines (33 loc) · 641 Bytes

React

Properties

PropTypes

You can make sure that you get a certain data type for your properties.

import React, {Component, PropTypes} from 'react';

class MyComponent extends Component {
    propTypes: {
        property: PropTypes.string,
        strictProperty: PropTypes.string.isRequired,
        interestingProperty: PropTypes.oneOf([
            'hey',
            'whats',
            'up?'
        ]).isRequired
    }
}
// alternatively

MyComponent.propTypes = {
    ...
}
});

Default property values

...
getDefaultProps: function() {
    return {
        property: 'value'
    };
},
...