reactjs - 反应原生 | 标题道具按钮必须是字符串
问题描述
我在我的 react native 项目中使用React Native Paper并在iOS
模拟器中运行。
单击时,Buttton
我正在导航到注册页面。当我单击时,出现以下错误。
title prop button must be string
代码:
<View style={styles.middle}>
<Animatable.View
animation="fadeInUpBig"
>
<Text style={styles.textContainer}>Welcome!</Text>
<View style={styles.formArea}>
<TextInput
left={<TextInput.Icon name="account-hard-hat" />} ƒ
style={styles.FormControl}
mode="outlined"
label="Username"
theme={{ colors: { primary: "#007fff" } }}
value=""
/>
<TextInput
left={<TextInput.Icon name="lock" />}
right={<TextInput.Icon name="eye-off" />}
style={styles.FormControl}
secureTextEntry={true}
mode="outlined"
label="Password"
theme={{ colors: { primary: "#007fff" } }}
value=""
/>
<Text style={styles.ForgotPwd}> Forgot Password? </Text>
<Button style={[styles.Button]} mode="contained">
<Text style={styles.ButtonText}> Sign In </Text>
</Button>
<Divider style={{ marginTop: 25, marginBottom: 25, backgroundColor: "#C6C6C6" }} />
<Text style={styles.NewAccTxt}> Don't have an account?</Text>
<Button onPress = {() => navigation.navigate('SignUp')} style={styles.Button} mode="contained">
<Text style={styles.ButtonText}> Create new one </Text>
</Button>
</View>
</Animatable.View>
截屏:
解决方案
你已经这样做了
<Button style={[styles.Button]} mode="contained">
<Text style={styles.ButtonText}> Sign In </Text>
</Button>
这不会起作用,因为 React Native 需要这样的东西
<Button title={styles.ButtonText} style={[styles.Button]} />
最好使用 TouchableOpacity 之类的东西,但按钮标题是必需的道具
推荐阅读
- sparql - 如何在 RDF 中存储与规则相关的数据?
- python - Django 按外键分组并返回其对象
- selenium - 带有 Mac 10.15.7 的 phantomjs,有效元素始终为 getText() 返回空字符串
- c - C语言中使用函数作为参数遍历二叉树
- python - 如何在没有睡眠的情况下使用异步 Django 视图?
- python - 如何检查 libtorrent python 中的估计剩余时间?
- flutter - 此解释器不支持常规 TensorFlow 操作。确保在推理之前应用/链接 Flex 委托
- webpack - Electron Jest Mock 模块
- excel - 运行时错误“1004”:对象“工作表”的方法“范围”失败 - VBA
- flutter - 被调用的构造函数不是