React.ComponentのcomponentDidMountメソッドを利用できるように、これを機能コンポーネントからクラスコンポーネントに変換する必要があります。React関数コンポーネントをクラスコンポーネントに変換する際の問題
const receivedStyle = {
marginRight: '0',
marginLeft: 'auto',
};
const receivedBubble = {
backgroundColor: '#709AFF',
color: 'white',
};
const receivedDate = {
marginRight: '0',
marginLeft: 'auto',
};
const MessageBubble = ({ message, received }) => (
<div className="message-bubble" style={received ? receivedStyle : null}>
<div className="bubble" style={received ? receivedBubble: null}>
{message.message}
</div>
<span className="date" style={received ? receivedDate: null}>{Moment(message.timestamp).startOf('minute').fromNow()}</span>
</div>
);
export default MessageBubble;
何が問題なのですか?単にui部分をレンダリングメソッドの中に置き、 'this.props'を使って小道具の値にアクセスしてください。 [**機能コンポーネントをクラスコンポーネントに変換する方法**]のドキュメントを確認してください(https://facebook.github.io/react/docs/components-and-props.html#functional-and-class-components) –