标识符'userInfo'已在React-native中声明

时间:2019-05-23 11:16:47

标签: react-native

当我运行我的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>

1 个答案:

答案 0 :(得分:0)

您有2个userInfo声明。一个来自os,另一个来自您声明userInfo常量的地方。

只需为您的常量命名其他名称即可

const userCredentials = {username: 'admin', password: '1234'};