按钮的标题支柱必须是一个字符串 - 本机反应

Rav*_*ran 12 reactjs 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);
Run Code Online (Sandbox Code Playgroud)

Fre*_*bda 12

我认为你太早关闭了Button标签.

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

只需在title属性后关闭标记即可

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

  • 注意:如果您的语法高亮显示不会使此错误跳到眼睛,您可以尝试使用不同的荧光笔或配色方案.这个问题很难在白色文本上看到,但应该通过适当的着色明显 (2认同)

小智 5

按钮名称应与标题关键字一起编写

例子 :

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

Button 标签内的 title="Press Me"


Viv*_*k S 5

事实上,就我而言,我错过了“标题” 道具。这就是它显示错误的原因。当我添加“标题”道具时,错误消失了。就是这样。