I currently initialize my state like this:
getInitialState: function () {
return {
conversations: {},
messages: {},
availableConversations: {}
}
},
If I do something like:
convosRef.on('value', snapshot => {
this.setState({ conversations: snapshot.val() });
});
It works as desired... however:
users: {
uid: {
conversations: {
conversationid: true,
conversationid2: true
}
}
}
I successfully get the desired object:
userSnapshot.child('conversations').forEach(function (conversationKey) {
var conversationRef = database.ref('conversations').child(conversationKey.key);
conversationRef.on('value', function (conversationsSnapshot) {
var conversation = conversationsSnapshot.val();
conversationLoadedCount = conversationLoadedCount + 1;
myObject[conversationKey.key] = conversation;
// console.log(conversationKey.key);
//this.state.conversations = conversation;
if (conversationLoadedCount === conversationCount) {
console.log("We've loaded all conversations");
}
});
this.setState({ conversations: myObject });
});
});
However. I receive two errors and I can't affect the state: First error: `FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'setState' of null``
And slightly similar:
Uncaught TypeError: Cannot read property 'setState' of null
I based my code on this excellent answer with no success whatsoever: Firebase two-way relationships / Retrieving data
This is running inside the componentDidMount function
.
Any suggestions on how to affect the state?