I have been referring a tutorial having 8 sections since a week, on which the code base depends from section 1. On the later section, I had created a ColorForm.js file as per the tutorial which includes the below code. When I have defined the ColorForm.PropTypes such as
ColorForm.propTypes = {
onNewColor: React.PropTypes.func.isRequired
}
the app thrown an error, undefined is not an object (evaluating _react.default.PropTypes.func)
On referring various post I came to know that I had to install 'prop-types', even though I am getting the above error. Can anyone help me to sort out this issue. Thanks in advance.
ColorForm.js
import React, {Component} from 'react'
import {
View,
Text,
StyleSheet,
TextInput
} from 'react-native'
export default class ColorForm extends Component {
constructor() {
super()
this.state = {
txtColor: ''
}
this.props.onNewColor(this.state.txtColor.toLowerCase())
this.submit = this.submit.bind(this)
}
submit() {
this.setState({txtColor: ''})
}
render() {
return(
<View style = {styles.container}>
<TextInput
style = {styles.txtInput}
placeholder = "Enter a color..."
onChangeText={(txtColor) => this.setState({txtColor})}
value = {this.state.txtColor}
/>
<Text style = {styles.button} onPress={this.submit}>Add</Text>
</View>
)
}
}
ColorForm.propTypes = {
onNewColor: React.PropTypes.func.isRequired
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-around',
backgroundColor: 'lightgrey',
height: 70
},
txtInput: {
flex: 1,
margin: 5,
padding: 5,
borderWidth: 2,
fontSize: 20,
borderRadius: 5,
backgroundColor: 'snow'
},
button: {
backgroundColor: 'darkblue',
margin: 5,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
color: 'white',
fontSize: 20
}
})