Created
May 10, 2018 18:11
-
-
Save majman/b00c891fee007fdaa3fd42e7ba4d9ec7 to your computer and use it in GitHub Desktop.
react classssses
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
| // Functional Components: Props Below | |
| const MyFunctionalComponent = ({ text, className, ...props }) => ( | |
| <div {...props} | |
| className={classNames('my-functional-component', className)} > | |
| {text} | |
| </div> | |
| ); | |
| MyFunctionalComponent.propTypes = { | |
| /** Text to render */ | |
| text: string, | |
| /** Optional className to add to the component for additional styling. */ | |
| className: string, | |
| }; | |
| MyFunctionalComponent.defaultProps = { | |
| text: '', | |
| className: '' | |
| }; | |
| // Components & PureComponents: Props up Tops™ | |
| export default class MyReactComponent extends Component { | |
| static propTypes = { | |
| /** Text to render */ | |
| text: string, | |
| /** Optional CSS classname for overriding and extending styles. */ | |
| className: string | |
| }; | |
| static defaultProps = { | |
| text: '', | |
| className: '' | |
| }; | |
| render() { | |
| const { className, text, ...props } = this.props; | |
| return ( | |
| <div {...props} | |
| className={classNames('my-react-component', className)}> | |
| {text} | |
| </div> | |
| ); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment