TypeError:未定义不是对象(正在评估'a.PropTypes.func')
那里有许多类似的问题,但是我的仍然不同,因为大多数问题都给出了诸如use之类的解决方案:
import PropTypes from 'prop-types';
作为单独的软件包,而不是来自:
import React,{ Component,PropTypes } from 'react';
自从开始我的项目以来,我已经开始这样做了。我仍然面临着同样的问题。以下是我使用原型的代码中的位置之一:
highlightColour: PropTypes.string.isrequired,onPress: PropTypes.func.isrequired
};
and
MonthYearPad.propTypes = {
highlightColour: PropTypes.string.isrequired,onmonthPress: PropTypes.func.isrequired,onYearPress: PropTypes.func.isrequired
};
编辑:我也用npm install --save prop-types
编辑:这也可以帮助您更好地理解:
render() {
return (
<View style={styles.container}>
<InputGroup
title="Month"
groups={monthGroups}
highlightColour={this.props.highlightColour}
onPress={this.props.onmonthPress}
/>
<InputGroup
title="Year"
groups={yearGroups}
highlightColour={this.props.highlightColour}
onPress={this.props.onYearPress}
isLast
/>
</View>
);
}
}
MonthYearPad.propTypes = {
highlightColour: PropTypes.string.isrequired,onYearPress: PropTypes.func.isrequired
};
export default MonthYearPad;
或迁移到流程