對於我的生活,我無法弄清楚爲什麼這一小部分代碼將無法正常工作!反應原生按鈕導致不變無效
我已經將問題隔離到Button元素(導入語句看起來不錯)。
我看到錯誤「不變的違規:元素類型無效:期望一個字符串(對於內置組件)或一個類/函數(對於複合組件),但得到:undefined。檢查Login的渲染方法。
import React, { ScrollView, Image, StyleSheet, Button } from "react-native";
import { connect } from "react-redux/native";
const onButtonClicked =() => {
};
class Login extends React.Component {
componentDidMount() {
}
render() {
return (
<ScrollView style={{flex: 1}}
contentContainerStyle={{
justifyContent: "center",
alignItems: "center"
}}>
<Image source={require('../../img/coin.png')}
resizeMode={Image.resizeMode.cover}
style={Styles.coinLogo} />
<Button title="Login default"
onPress={() => {}} />
</ScrollView>
);
}
}
Login.propTypes = {
dispatch: React.PropTypes.func
};
Login.defaultProps = {
dispatch:() => {}
}
const Styles = StyleSheet.create({
coinLogo: {
marginTop: 50,
height: 200,
width: 200,
},
loginButton: {
marginTop: 50,
},
});
export default connect((state) => ({
}))(Login);
不是。它看起來像我的項目甚至沒有引用React包,所以我安裝了它,但結束了相同的錯誤。 – Steven
我正在使用此處找到的樣板項目:https://github.com/FormidableLabs/formidable-react-native-app-boilerplate.git 您可以通過向app.js添加按鈕來快速查看問題。 並感謝您花時間回答! – Steven
與原生變化的反應速度相比,這是一個非常古老的樣板。你有沒有試過將console.log作爲martinarroyo的建議。如果你沒有更新該樣板的依賴關係,那麼肯定Button是未定義的,如果你不想更新依賴項,你應該使用TouchableOpacity或TouchableHighlight而不是Button。 – diedu