A
A
antonpanamo2021-12-28 23:40:56
React Native
antonpanamo, 2021-12-28 23:40:56

How to change the text in a component when a button is clicked?

How can I change this variable to change the value in the component?

this.textValue = g

import Checkbox from 'expo-checkbox';
import React, { useState } from 'react';
import { StyleSheet, Text, View, Alert, Modal,  Pressable, TextInput, Switch } from 'react-native';

export default function App() {
  
   const [number, onChangeNumber] = React.useState(null);
   const [counter1, setCounter1] = useState(0);
   
    var textValue = useState (' мой текст 123');
 
 this.handleClick = (g) => {
   this.textValue = g
    console.log('значение this:', g);
  }
   

  return (
  <>

    <Text>{textValue}</Text>

      <button onClick={() => this.handleClick('clickclick')}>
        Нажми на меня
      </button>
   
   </>


  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginHorizontal: 16,
    marginVertical: 32,
  },
  section: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  paragraph: {
    fontSize: 15,
  },
  checkbox: {
    margin: 8,
  },
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question