【发布时间】:2018-11-04 02:53:31
【问题描述】:
我尝试显示在我提交的渲染中还有多少字符需要输入,但我得到了_this.setState is not a function. (in '_this.setState({value: value})','_this.setState' is undefined)
这是我的渲染
const renderField = ({ label, keyboardType, name, meta: { touched, error }, input: { onChange, ...restInput } }) => {
this.state = {
value: ''
}
return (
<View style={{ flexDirection: 'column', height: 70, alignItems: 'flex-start' }}>
<View style={{ flexDirection: 'row', alignItems: 'center', borderColor: 'black', borderBottomWidth: 1, }}>
<TextInput style={{ height: 37, width: 295, paddingLeft: 10, fontSize: 20, height: 350, justifyContent: "flex-start" }}
keyboardType={keyboardType} value={this.state.value} onChangeText={(value) => this.setState({ value })} {...restInput}
placeholder={label} numberOfLines={10} multiline={true} maxLength={100}
>
</TextInput>
</View>
<Text>
Characters Left: {this.state.value.length}/100
</Text>
{touched && ((error && <Text style={{ color: 'red', }}>{error}</Text>))}
</View>);
};
【问题讨论】:
标签: react-native redux redux-form