Skip to content

Instantly share code, notes, and snippets.

@kennydee kennydee/styled.js
Created May 23, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.