Created
December 19, 2015 16:09
-
-
Save josefrichter/3ca9c6a91800a49bfbee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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