我是新来的,我希望代码尽可能短。我们正在编写带有许多props的react组件。问题是我的同事不断填写代码,这对我来说似乎非常不必要。那么将 null 设置为所有可用值还是仅使用 propTypes 来定义属性类型是否正确?因为我没有看到这样的使用示例,我认为这是不好的做法。
FormAutonumeric.defaultProps = {
validationRules: null,
onBlur: null,
onFocus: null,
inputClasses: null,
showErrors: false,
numericType: null,
isFormValid: null,
placeholder: null,
onChange: null,
disabled: null,
children: null,
vMin: null,
vMax: null,
prefix: null,
suffix: null
};
FormAutonumeric.propTypes = {
validationRules: PropTypes.shape({
[PropTypes.string]: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.bool
])
}),
onBlur: PropTypes.func,
onFocus: PropTypes.func,
inputClasses: PropTypes.string,
showErrors: PropTypes.bool,
numericType: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
isFormValid: PropTypes.func,
id: PropTypes.string.isRequired,
placeholder: PropTypes.string,
onKeyUp: PropTypes.func.isRequired,
onChange: PropTypes.func,
disabled: PropTypes.bool,
children: PropTypes.element,
vMin: PropTypes.string,
vMax: PropTypes.string,
prefix: PropTypes.string,
suffix: PropTypes.string
};