How can I display information from a database in Firebase in React Native within a Text?

1

How to read data from a RealTimeDatabase in

asked by George Rozo 13.08.2018 в 06:27
source

1 answer

1

Short answer

You must use setState instead of changing the state directly.

componentDidMount(){
  const { uid } = firebaseAuth.currentUser
  this.getUserRef().child(uid).once('value',function(snapshot){
    this.setState({ dataUser: snapshot.val() })
  })
}

Long answer

A key concept in React (and therefore, in React Native as well) is that of immutability .

In particular, the internal state of the React components (the state ) must be immutable , that is, it must not be mutated / modified directly but replaced every time we want to make a change . For this, React provides us with the method setState (documented here ) that is responsible for updating the same and that generates as a consequence a new render that makes the changes are reflected in the UI.

    
answered by 15.08.2018 / 17:51
source