Skip to content

Instantly share code, notes, and snippets.

@goldhand
Created May 17, 2016 16:34
Show Gist options
  • Save goldhand/00fc73da0771f70b921eaa1c7d04f3d7 to your computer and use it in GitHub Desktop.
Save goldhand/00fc73da0771f70b921eaa1c7d04f3d7 to your computer and use it in GitHub Desktop.
Really sweet way of structuring property naming
import React, {Component, PropTypes} from 'react';
export default class GalleryItem extends Component {
static propTypes = {
src: PropTypes.string,
}
render() {
return (
<img {...this.props} />
);
}
}
// Another version
export default function GalleryItem({
src,
height,
width,
}) {
return (
<img {...arguments[0]} />
);
}
GalleryItem.propTypes = {
src: PropTypes.string.isRequired,
height: PropTypes.number,
width: PropTypes.number,
};
// or super shorthand, you loose proptypes validation...
export const GalleryItem = (props) => <img {...this.props} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment