Skip to content

Instantly share code, notes, and snippets.

@diegohaz
Last active June 22, 2018 09:06
Show Gist options
  • Save diegohaz/59e78e397c16ce2e6d854963f866f8aa to your computer and use it in GitHub Desktop.
Save diegohaz/59e78e397c16ce2e6d854963f866f8aa to your computer and use it in GitHub Desktop.
const callAll = (...fns) => (...args) => fns.forEach(fn => fn && fn(...args));
const internalOnLoad = () => console.log("loaded");
const Avatar = ({ className, style, onLoad, ...props }) => (
<img
className={`avatar ${className}`}
style={{ borderRadius: "50%", ...style }}
onLoad={callAll(internalOnLoad, onLoad)}
{...props}
/>
);
Avatar.propTypes = {
src: PropTypes.string.isRequired,
alt: PropTypes.string.isRequired,
className: PropTypes.string,
style: PropTypes.object,
onLoad: PropTypes.func
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment