Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created December 19, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefrichter/3ca9c6a91800a49bfbee to your computer and use it in GitHub Desktop.
Save josefrichter/3ca9c6a91800a49bfbee to your computer and use it in GitHub Desktop.
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