我有一个错误,真的不知道为什么。这是一个柠简单的代码中庸之道测试反应过来人,想创建一个类谁打电话的其他类和UNE一个按钮来增加数量:React Native JS:预计一个组件类,得到[对象对象]
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
TouchableHighlight,
Text,
View
} from 'react-native';
export default class Apprentissage1 extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcolm bitch
</Text>
<Product name="Product 1"/>
<Product name="Product 2"/>
</View>
);
}
}
class Product extends Component {
constructor(props) { //Constructeur
super(props);
this.state = {
quantity: 0
};
}
addToCart(){
this.setState({
quantity: this.state.quantity + 1
})
}
render(){
return(
<View style={styles.container}>
<h2>{this.props.name}</h2>
<p>Quantity: {this.state.quantity}</p>
<TouchableHighlight onPress={this.addToCart.bind(this)}>
Add To cart
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('Apprentissage1',() => Apprentissage1);
感谢的对你有所帮助:)
你不能渲染的反应,本机应用程序的HTML,而无需使用的WebView组件...此错误是在你的产品组件 – Maxwelll
尝试从''删除'''出口default'''相关的渲染功能'导出默认类Apprentissage1扩展组件{'''并用原生组件替换html组件'''''' –