在设备上运行时出现如下错误“按钮的 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/