I have watched this talk and I am right now trying to use react components to show a list of messages (in a chat). So I have two react components:
1) The "Message" component that is basicaly an li with the message props (dateTime, userName, and body);
var Message = React.createClass({
render: function () {
return (
<li className="right clearfix">
<span className="chat-img pull-right">
<div className="chat-body clearfix">
<div className="header">
<small className=" text-muted"> sent {this.props.dateTime}
</small>
<strong className="primary-font">{this.props.userName</strong>
</div>
<p>{this.props.body}</p>
</div>
</li>
);
}
});
2) The "Messages" component which is a ul that lists all the chat messages
var Messages = React.createClass({
render() {
var createMessage = ({dateTime, userName, body, id}) => <Message key={id} dateTime={dateTime} userName={userName} body={body} />;
return <ul className="chat">{this.props.messages.map(createMessage)}</ul>;
}
});
In my view this is what I have:
<%= react_component('Messages', { messages: @messages }) %>
Nothing too complicated. The problem is that I don't know how to change the "message" component attributes. For example if I want to change the format of the messages created_at attributes ? Or the users names based on a model method ? Do I have to parse these "props" with json from the controller ?
I'm just trying to figure out how react could work with my rails app, please don't hesitate to leave any suggestion/info. Thanks in advance