Итак, у меня есть два компонента, и попытка проверки типов пропов дает ошибку:
TypeError: TypeError: Невозможно прочитать свойство 'style' из неопределенного
Это мой компонент HomeScreen:
import React, { Component } from 'react';
import {
Image,
Platform,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
import { RobotoText } from '../components/StyledText';
export default class HomeScreen extends Component {
render() {
const { container } = styles;
return (
<View style={container}>
<RobotoText style={{ color: 'green' }}> Test </RobotoText>
</View>
);
}
}
И файл StyledText, в котором происходит ошибка:
import React from 'react';
import { Text } from 'react-native';
import PropTypes from 'prop-types';
const MonoText = props => {
const { style } = props;
return <Text {...props} style={[style, { fontFamily: 'space-mono' }]} />;
};
const RobotoText = props => {
const { style } = props;
return <Text {...props} style={[style, { fontFamily: 'Roboto' }]} />;
};
MonoText.defaultProps = {
style: { color: 'black' }
};
MonoText.propTypes = {
style: Text.PropTypes.style
};
RobotoText.defaultProps = {
style: { color: 'black' }
};
RobotoText.propTypes = {
style: Text.PropTypes.style
};
export { MonoText, RobotoText };
Как правильно определить этот propTypes?