i need to get online status of user here's function where i listen online status
onlineStatus(id) {
app.database().ref('users').child(id).child('connections').on('value', (snapshot) => {
return snapshot.val();
})
}
but when i try to use this function in return function i get undefined value
{this.state.diologs.map(i =>
this.state.searchResult.length === 0 && this.state.isDiologOpen === false &&
<div className="resultField" >
<img src="/images/noavatar.png" id="userImage" />
<p className="userName">{i.name} {i.surname} </p>
<p>{i.lastMessage}</p>
<button onClick={() => this.writeMessage(i)}>Написать сообщение</button>
{this.onlineStatus(i.id) ? <p>Online</p> : <p>Offline</p>}
the problem is in this line
{this.onlineStatus(i.id) ? <p>Online</p> : <p>Offline</p>}
lang-js
once()instead ofon()to query a single time and return a promise to the caller with the data from the query.onlineStatusdoesn't return any data. The return statement insideonlineStatuscurrently just return for the callback instead of the method. I don't have enough information about the context of your problem but seems like your approach is not effective and even not doable. React rendering doesn't work that way.