Skip to content

Components #7

Closed
Closed

Description

@mxstbr

Currently, doing this won't work (React throws an error that you have to return an element, null or etc.):

const Component = (props) => {
  return styled.div`
    background-color: ${props.bg};
  `;
}

You have to do this to make it work:

const Component = (props) => {
  const Primitive = styled.div`
    background-color: ${props.bg};
  `;
  return <Primitive />;
}

Which seems unnecessary, verbose and confusing. I'm not sure if we can do something against this though?

Activity

  1. geelen commented on Sep 13, 2016

    @geelen
    Member

    I missed this. This is awful. Let's fix this.

  2. geelen commented on Sep 14, 2016

    @geelen
    Member

    Ok so given we must return a component (because we can't pass props to the rendered element if we don't, see #19), we need another way to conditionally apply styles.

    This works but is ugly:

    const A = props => styled.div`
      color: ${props.color || 'black'};
    `(props)

    Because styled.div``` returns props => createElement()` you can call it directly passing the props onwards and it's all ok. But it looks horrible.

    We could make this work too:

    const A = styled.div(props => `
      color: ${props.color || 'black'};
    `)

    Except now we don't have a tagged template literal to work with. So if we want to use anything advanced with the interpolations we'd have to do styled.div(props => css...). I'm still not convinced that we should go down the all-strings-all-the-time route.

    So we need a better way of doing conditional styles from props.

  3. geelen commented on Sep 14, 2016

    @geelen
    Member

    This is a better way to do conditionals: #24

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions