question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with styled-components

See original GitHub issue

This issue seems to affect a lot of the components provided by react-native-elements. Here’s an example with <ListItem />:

If I use styled-components with a <ListItem/>, the default container style isn’t used anymore.

Here’s how the styled component is created:

const StyledListItem = styled(ListItem).attrs({
  titleStyle: { /* ... */ },
})``;

Here’s the result when using <StyledListItem> for my first element in the list: screen shot 2017-10-27 at 6 15 01 pm

As you may see, the bottom border defined as default is lost.

The problem is located here: https://github.com/react-native-training/react-native-elements/blob/master/src/list/ListItem.js#L97-L103

When using styled-components, attributes gets automatically passed this value:

{ style: [ 540, undefined ],
  innerRef: [Function],
  children: undefined }

so the default style gets overrided.

Solution

An obvious solution would be to spread attributes first, then define your own props, as you definitely don’t want them to be overridden (or do you?)

    <Component
      {...attributes}
      onLongPress={onLongPress}
      onPress={onPress}
      underlayColor={underlayColor}
      style={[styles.container, containerStyle && containerStyle]}
    >

I’d happily work on a PR for this, but i’d like to make sure that it’s not done on purpose on the first place.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
machourcommented, Nov 5, 2017

@Monte9 so far so good on GitPoint. Thank you all for this quick handling, such quick, much love ❤️

0reactions
Monte9commented, Nov 5, 2017

RNE x GitPoint = 💯

Happy to help! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · styled-components/styled-components - GitHub
Issues list · customSyntax for Stylelint v14+ · Can't use <use> element with styled-components · Upgrading react dependency to 18.1 · css animation...
Read more >
The Pros and Cons of Using Styled Components in React
For applications that use styled components, the browser downloads the CSS and parses it using JavaScript before injecting them into the page.
Read more >
FAQs - styled-components
Commonly asked questions about styled-components.
Read more >
My problem with styled-components : r/reactjs - Reddit
My problem with styled-components · Colocate CSS styles inline with components · Easily extend and customize existing components · Props and theme ...
Read more >
The styled-components Happy Path - Josh W Comeau
styled -components is a wonderfully powerful styling library for React, ... Here's another way to solve the problem, using CSS variables:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found