Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the title prop of a button must be a string - react native

Tags:

while run on device getting error like this "the title prop of a button must be a string - 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); 
like image 928
Ravindhiran Avatar asked May 10 '17 14:05

Ravindhiran


People also ask

How do you style a button title in React Native?

The closest we can get to styling a <Button /> exported from React Native is with the color prop. Below is an example of two buttons on Android, iOS, and the web. The first button is the default <Button /> and the second is another default <Button /> with its color prop set to "red" .

How do you customize a button in React Native?

To create custom buttons, you need to customize the <TouchableOpacity /> component and include the <Text /> component inside of it to display the button text. const AppButton = ({ onPress, title }) => ( <TouchableOpacity onPress={onPress} style={styles. appButtonContainer}> <Text style={styles.

How do you call a component on button click in React Native?

Building Out the Basic Structure /* Write a button component */ import React from 'react'; const Button = (props) => { return ( <button>{props. text}</button> ); } export {Button}; What is this? import React from 'react'; const ListComponent = (props) => { return ( <div> <h1>{props.


1 Answers

I think you have closed the Button tag too early.

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

Just close the tag after the title attribute

<Button   style={{fontSize: 20, color: 'green'}}   styleDisabled={{color: 'red'}}   onPress={() => this._handlePress()}   title="Press Me" >   Press Me </Button> 
like image 133
Freeman Lambda Avatar answered Sep 20 '22 14:09

Freeman Lambda