Skip to content

Instantly share code, notes, and snippets.

@majman
Created May 10, 2018 18:11
Show Gist options
  • Select an option

  • Save majman/b00c891fee007fdaa3fd42e7ba4d9ec7 to your computer and use it in GitHub Desktop.

Select an option

Save majman/b00c891fee007fdaa3fd42e7ba4d9ec7 to your computer and use it in GitHub Desktop.
react classssses
// 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