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

标签 reactjs react-native

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

相关文章:

React-native 搜索栏和 flatList 问题

reactjs - Create-React-App:在本地机器上部署时出现 ESlint 错误

javascript - 如何使用 Redux-Form 保存复合对象?

javascript - React Navigation 中的过渡背景颜色

javascript - 超过 2 个值的三元运算符替代方案

react-native - 终极版/传奇 : How to fire an action (put) inside a callback without channels (use sagas as normal generator functions)

reactjs - 我可以确定下次 React 渲染时它将使用最新的状态值吗?

javascript - 如何将 jQuery 与 React js 集成?

javascript - React - 如何确定组件是否是无状态/功能性的?

reactjs - 使用 React,在使用 react-transition-group 时,在 StrictMode 中不推荐使用 findDOMNode 作为警告