Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Last active March 31, 2017 06:55
Show Gist options
  • Save tmeasday/ca66f3c4609dfea4bda873f8088a8de2 to your computer and use it in GitHub Desktop.
Save tmeasday/ca66f3c4609dfea4bda873f8088a8de2 to your computer and use it in GitHub Desktop.
Presentational split
import React, { Component, PropTypes } from 'react';
import $ from 'jquery';
const BUMP_URL = (id) => `/bump/${id}`;
const Avatar = ({ name, avatar_url, onBump }) => (
<div className="avatar image-link">
<img src={avatar_url} title={name} />
<span class="image-action" onClick={onBump}>Bump</span>
</div>
);
Avatar.propTypes = {
name: PropTypes.string.isRequired,
avatar_url: PropTypes.string.isRequired,
onBump: PropTypes.func.isRequired,
};
export default class BumpingAvatar extends Component {
static props = {
userId: PropTypes.string.isRequired,
}
bump() {
$.ajax(BUMP_URL(this.props.userId), { type: post });
}
render() {
return <Avatar {...this.props} onBump={() => this.bump()} />;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment