Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const _fbBase = new Firebase('https://•••••••••.firebaseIO.com');
_fbBase.child('users/'+newUserID+'/conversations').on('value', function(snap){
var obj = snap.val();
var arr = Object.keys(obj).map(function (key) {return obj[key]}); // just converting to array - http://stackoverflow.com/a/26166303
_this.setState({conversations: arr});
});
class ConvoList extends React.Component {
constructor(props) {
super(props);
}
onChildChanged(passedData) {
// passedData here should be the clicked conversationID
}
// here I pass each indiviual conversation to the ConvoListItem component, but the ID probably gets lost
render() {
<div>
{this.props.conversations.map((convo) => <ConvoListItem convo={convo} callbackParent={this.onChildChanged} />)}
</div>;
}
}
class ConvoListItem extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
onClick() {
// I need the conversationID here so that I can pass it up to parent
this.props.callbackParent(conversationID);
}
render() {
return <div className="convo-list-item" onClick={this.onClick}>
<p>{this.props.convo.lastMessage}</p>
</div>;
}
}
// in render() method of Application class:
<ConvoList conversations={this.state.conversations} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.