Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 对承包商的说法作出反应'';错误_React Native - Fatal编程技术网

React native 对承包商的说法作出反应'';错误

React native 对承包商的说法作出反应'';错误,react-native,React Native,这是我想要实现添加国家和地区下拉列表的代码。我在7,8行遇到错误,表示分号丢失。我想要帮助,因为我是reactnative的初学者 import React,{ Component } from 'react'; import { CountryDropdown, RegionDropdown } from 'react-country-region-selector'; import { StyleSheet, Text, TextInput, View } from 'react-nativ

这是我想要实现添加国家和地区下拉列表的代码。我在7,8行遇到错误,表示分号丢失。我想要帮助,因为我是reactnative的初学者

import React,{ Component } from 'react';
import { CountryDropdown, RegionDropdown } from 'react-country-region-selector';
import { StyleSheet, Text, TextInput, View } from 'react-native';

export default function App extends Component() {
  constructor(props) {
    super(props);
    this.state = { country: '', region: '' };
  };
  selectCountry=(val)=>{
    this.setState({ country: val });
  };

  selectRegion=(val)=>{
    this.setState({ region: val });
  };
  const { country, region } = this.state;
  return (
    <View style={styles.container}>
      <View style={styles.line}>
        <Text style={styles.text}>Enter name:</Text>
        <TextInput 
        style={styles.input}
        placeholder='e.g. John Doe'
        />
      </View>
      <View style={styles.line}>
        <Text style={styles.text}>Enter Age:</Text>
        <TextInput 
        keyboardType='numeric'
        style={styles.input}
        placeholder='2'
        />
      </View>
      <View style={styles.line}>
        <Text style={styles.text}>Enter Country:</Text>
        <CountryDropdown
          value={country}
          onValueChange={(val) => this.selectCountry(val)} />
      </View>
      <View style={styles.line}>
        <Text style={styles.text}>Enter Region:</Text>
        <RegionDropdown
          country={country}
          value={region}
          onValueChange={(val) => this.selectRegion(val)} />
      </View>
      
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex:1,
    backgroundColor: '#fff',
    alignItems:'center',
    justifyContent:'center',
  },
  line:{
    flexDirection:'row',
    flex:0,
    marginBottom:5,
  },
  text:{
    flex:1,
  },
  input:{
    flex:1,
    width:70,
    borderBottomWidth:1,
    borderBottomColor:'#777',
  },
  
});
import React,{Component}来自'React';
从“反应国家/地区选择器”导入{CountryDropdown,RegionDropdown};
从“react native”导入{样式表、文本、文本输入、视图};
导出默认函数应用程序扩展组件(){
建造师(道具){
超级(道具);
this.state={国家:'',地区:'};
};
选择国家=(val)=>{
this.setState({country:val});
};
选择区域=(val)=>{
this.setState({region:val});
};
const{country,region}=this.state;
返回(
输入名称:
输入年龄:
输入国家:
this.selectCountry(val)}/>
输入区域:
this.selectRegion(val)}/>
);
}
const styles=StyleSheet.create({
容器:{
弹性:1,
背景颜色:“#fff”,
对齐项目:'中心',
辩护内容:'中心',
},
行:{
flexDirection:“行”,
弹性:0,
marginBottom:5,
},
正文:{
弹性:1,
},
输入:{
弹性:1,
宽度:70,
边界宽度:1,
borderBottomColor:“#777”,
},
});

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////您使用的是类组件,但将其称为函数

将导出默认函数App extends Component()更改为导出默认类App extends Component(){

还添加一个render()函数,并使用适当的括号括起来

下面是新代码

import React,{ Component } from 'react';
import { CountryDropdown, RegionDropdown } from 'react-country-region-selector';
import { StyleSheet, Text, TextInput, View } from 'react-native';

export default class App extends Component() { <-- change here
  constructor(props) {
    super(props);
    this.state = { country: '', region: '' };
  };
  selectCountry=(val)=>{
    this.setState({ country: val });
  };

  selectRegion=(val)=>{
    this.setState({ region: val });
  };
  render() { <-- add here
    const {country, region} = this.state;

    return (
      <View style={styles.container}>
        <View style={styles.line}>
          <Text style={styles.text}>Enter name:</Text>
          <TextInput
            style={styles.input}
            placeholder='e.g. John Doe'
          />
        </View>
        <View style={styles.line}>
          <Text style={styles.text}>Enter Age:</Text>
          <TextInput
            keyboardType='numeric'
            style={styles.input}
            placeholder='2'
          />
        </View>
        <View style={styles.line}>
          <Text style={styles.text}>Enter Country:</Text>
          <CountryDropdown
            value={country}
            onValueChange={(val) => this.selectCountry(val)}/>
        </View>
        <View style={styles.line}>
          <Text style={styles.text}>Enter Region:</Text>
          <RegionDropdown
            country={country}
            value={region}
            onValueChange={(val) => this.selectRegion(val)}/>
        </View>

      </View>
    );
  } <-- add here
}

const styles = StyleSheet.create({
  container: {
    flex:1,
    backgroundColor: '#fff',
    alignItems:'center',
    justifyContent:'center',
  },
  line:{
    flexDirection:'row',
    flex:0,
    marginBottom:5,
  },
  text:{
    flex:1,
  },
  input:{
    flex:1,
    width:70,
    borderBottomWidth:1,
    borderBottomColor:'#777',
  },

});
import React,{Component}来自'React';
从“反应国家/地区选择器”导入{CountryDropdown,RegionDropdown};
从“react native”导入{样式表、文本、文本输入、视图};
导出默认类应用程序扩展组件(){{
this.setState({country:val});
};
选择区域=(val)=>{
this.setState({region:val});
};
render(){
输入区域:
this.selectRegion(val)}/>
);
}