Created
May 17, 2016 16:34
-
-
Save goldhand/00fc73da0771f70b921eaa1c7d04f3d7 to your computer and use it in GitHub Desktop.
Really sweet way of structuring property naming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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