Skip to content

Instantly share code, notes, and snippets.

@darekrossman
Last active November 23, 2016 14:30
Show Gist options
  • Save darekrossman/ff8e61c89c59452d12a48f716ded83e5 to your computer and use it in GitHub Desktop.
Save darekrossman/ff8e61c89c59452d12a48f716ded83e5 to your computer and use it in GitHub Desktop.
A React snippet for scaffolding out a stateless functional component, using Flow for prop types and custom HOCs for themability.
'Stateless React Component':
'prefix': 'srcc'
'body': '''
// @flow
import React, { PropTypes } from 'react';
import { compose } from 'recompose';
import { withStyles } from '_util/HOCs';
import { FlexBox } from '@madmobilenpm/mmui';
type Props = {
};
type WrappedProps = {
styles: Styles
};
const componentStyles: StyleFn = ({ theme: { colors } }) => ({
container: {}
});
export const BaseComponent: Component<WrappedProps> = ({ styles }) =>
<FlexBox style={styles.container}>
Hello :)
</FlexBox>;
export const enhancer = compose(
withStyles(componentStyles)
);
const WrappedComponent: Component<Props> = enhancer(BaseComponent);
export default WrappedComponent;
'''
@darekrossman
Copy link
Author

Still trying to find the right pattern for typing props that should be provided to the component from the outside - and props that are added to the component from HOCs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment