当我运行我的react-native代码时,它说“标识符'userInfo'已经被声明”。我该怎么解决?
我想从用户那里获取用户名和密码,然后检查现有的admin和1234用户名和密码。
import { userInfo } from 'os'; //libraries
import { CreateSwitchNavigator, createStackNavigator, createAppContainer} from 'react-navigation';
const userInfo = {username: 'admin', password: '1234'};
class loginScreen extends Component {
constructor (props) {
super(props);
this.state= {username: '', password:''}
}
<TextInput style={styles.input}
placeholder='Username'
onChangeText={(username=> this.setState( {username}))}
value={this.state.username}
/>
<TextInput style={styles.input}
placeholder='Password'
onChangeText={(password=> this.setState( {password}))}
value={this.state.password}
/>
<TouchableOpacity
style={styles.btnEnter}
onPress={this._signin}
>
<Text style={styles.btnEnterText}> Enter</Text>
</TouchableOpacity>
答案 0 :(得分:0)
您有2个userInfo
声明。一个来自os
,另一个来自您声明userInfo
常量的地方。
只需为您的常量命名其他名称即可
const userCredentials = {username: 'admin', password: '1234'};