我有一個錯誤,真的不知道爲什麼。這是一個檸簡單的代碼中庸之道測試反應過來人,想創建一個類誰打電話的其他類和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組件'''''' –