Skip to content

Instantly share code, notes, and snippets.

@kennydee
Created May 23, 2017 04:07
Show Gist options
  • Save kennydee/c1764dcde58adfd8341d48629313c6b4 to your computer and use it in GitHub Desktop.
Save kennydee/c1764dcde58adfd8341d48629313c6b4 to your computer and use it in GitHub Desktop.
Styled component without styled components for React Native
import React, { PropTypes } from 'react';
import * as theme from '../theme';
const styled = (Component, styler) => props => {
const propsWithTheme = { ...props, theme };
const style = typeof styler === 'function' ? styler(propsWithTheme) : styler;
// React doesn't support "forwarding" ref for now
if (propsWithTheme.innerRef) {
propsWithTheme.ref = propsWithTheme.innerRef;
}
const component = <Component {...propsWithTheme} style={[style, propsWithTheme.style]} />;
component.propTypes = {
style: PropTypes.object,
};
component.defaultProps = {
style: {},
};
return component;
};
export default styled;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment