0
It is necessary to create an element in the state in its component. Following example:
import React, { Component } from "react";
import { Button, Text, View } from "react-native";
class App extends Component {
constructor() {
super();
this.state = {
contG1: 0
};
}
somaG1() {
this.setState({contG1:this.state.contG1+1})
}
render() {
return (
<View>
<Text>Valor contG1: {this.state.contG1}</Text>
<Button onPress={() => this.somaG1()} title="Clique para somar" />
</View>
);
}
}
export default App;
You can also see working online.
The state
has the role of controlling the state of that component, in this case the App component of your application. It is important to remember that it is immutable, being changed with the function setState
.
For more information about the state, you can access documentation.
Could you please put your code to facilitate assist in the response?
– Felipe Avelar
Philip is what is in the image above, not appearing ?
– Fabricio Carneiro
We usually do this with state: https://facebook.github.io/react-native/docs/state
– Lucas de Carvalho
@Lucasdecarvalho thanks man, but I think I still don’t understand.
– Fabricio Carneiro