gpt4 book ai didi

reactjs - 按钮的 title 属性必须是字符串 - React Native

转载 作者:行者123 更新时间:2023-12-03 13:14:24 26 4
gpt4 key购买 nike

在设备上运行时出现如下错误“按钮的 title 属性必须是字符串 - react native

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Button,
View
} from 'react-native';

export default class sample extends Component {

render() {
return (
<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}>
title="Press Me"
</Button>
);
}


_handlePress() {
console.log('Pressed!');
}
}

AppRegistry.registerComponent('sample', () => sample);

最佳答案

我认为您太早关闭了 Button 标签。

<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}> // <-- closed tag here
title="Press Me"
</Button>

只需关闭 title 属性后面的标签

<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}
title="Press Me"
>
Press Me
</Button>

关于reactjs - 按钮的 title 属性必须是字符串 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43895772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com