Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React Native: How can I create a new Text component from a function?

$
0
0

I want to create a new Text Component through a function called by pressing a button.

import React, { Component } from 'react';import { StyleSheet, Text, View, Button } from 'react-native';export default class App extends React.Component {  constructor() {    super();    this.clicks = 0;  }  addText() {    return (      // something to add a new Text component to the View    )  }  ButtonPress() {    this.clicks++;    if (this.clicks > 0 && this.clicks % 20 == 0) {      this.addText();    }  }  render() {    return (<View style={styles.container}><Button          title="Click me"          onPress={this.ButtonPress.bind(this)}        /></View>    );  }}

I know it's possible by making an arrow function in the onPress from the button, but I want to do it exclusively from a function.Is it possible? If so, how?Any help is appreciated.Thanks!


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>