【发布时间】:2020-09-06 13:16:38
【问题描述】:
我有以下代码
import React from 'react';
import { StyleSheet,Text,View,SafeAreaView,ScrollView ,Image ,TextInput} from 'react-native';
import Entypo from 'react-native-vector-icons/Entypo';
import { Neomorph } from 'react-native-neomorph-shadows';
export const HomeScreen = ({ navigation }) => {
state = {
fname : "",
sname : "",
}
return( <SafeAreaView style={{ alignSelf: "stretch" }}>
<View style={styles.card}>
<Neomorph style={styles.neomorph} >
<Text style={styles.input_title}>First Name</Text>
<Neomorph inner style={styles.input} >
<TextInput
style={{ borderColor: 'transparent', borderWidth: 1 ,width: "100%" ,borderRadius: 8,height: 50,paddingLeft: 10,fontSize: 18,fontWeight:"bold",color:"#ffffff"}}
onChangeText={(nextValue) => this.setState({fname: nextValue})}
value={this.state.fname}
/>
</Neomorph>
</Neomorph>
</View>
<View style={styles.card}>
<Neomorph style={styles.neomorph} >
<Text style={styles.input_title}>Second Name</Text>
<Neomorph inner style={styles.input} >
<TextInput
style={{ borderColor: 'transparent', borderWidth: 1 ,width: "100%" ,borderRadius: 8,height: 50,paddingLeft: 10,fontSize: 18,fontWeight:"bold",color:"#ffffff"}}
onChangeText={(nextValue) => this.setState({sname: nextValue})}
value={this.state.sname}
/>
</Neomorph>
</Neomorph>
</View>
</SafeAreaView>
)
}
TypeError: _this.setState is not a function. (In '_this.setState({
fname: nextValue
})', '_this.setState' is undefined)
谁能帮我解决这个问题 提前致谢
【问题讨论】:
标签: react-native react-native-android setstate