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.

[Feature] Styling components with props other than style

See original GitHub issue

Thank you for this amazing lib!!

Could we style components with props other than style? If not, I am making a feature request.

I am trying to style a Swipeable component. Naturally I wanna keep using NativeWind with all the theme setup. Basically, I would like to use something similar to sx hook in Dripsy but with tailwind class name. eg.

<FlatList
    contentContainerStyle={sx("flex-1 h-full")}
    data={data}
    renderItem={renderItem}
  />

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
marklawlorcommented, Oct 24, 2022

Styled will not style nested props. You can fix your issues by simply evaluating the prop you wish to style

const StyledNavigator = styled(
  ({ tabBarLabelStyle, ...props }) => <TabNavigator.Navigator {...props} screenOptions={{ ...props.screenOptions, tabBarLabelStyle }} />, 
  {
    props: {
      tabBarLabelStyle: true
    }
  }
)
1reaction
ChrisYohanncommented, Oct 19, 2022

Hi @marklawlor , I did not want to reopen an issue because my problem looks pretty similar, but do you have an example when you have to pass a style object (and you cannot derive a styled component to embed tailwind class names ?)

For example, coming from tailwind-react-native-classnames, I have a BottomTabNavigator from @react-navigation/bottom-tabs and I’m styling the TabBarLabel like this :

    <TabNavigator.Navigator
      screenOptions={{
        headerTitleAlign: 'center',
        headerShadowVisible: false,
        tabBarLabelStyle: tw.style('text-center text-xs font-display'),
      }}
    >
    //...
   </TabNavigator.Navigator>

Do you have an idea of how I can achieve it with nativewind ?

Thanks, and awesome work by the way 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 awesome features of styled-components - LogRocket Blog
8 awesome features of styled-components · 1. Style inheritance · 2. Passing props · 3. Theming · 4. Global styling · 5. Switching...
Read more >
Advanced Usage - styled-components
styled-components generates an actual stylesheet with classes, and attaches those classes to the DOM nodes of styled components via the className prop. It ......
Read more >
Support for class props other than className · Issue #3179 ...
Currently styled-components only supports styling via the className prop requiring hacky workarounds to make use of the other props. Take for ...
Read more >
How To Use Styled-Components In React - Smashing Magazine
Adapting Based on Props # Styled components are functional, so we can easily style elements dynamically. Let's assume we have two types of ......
Read more >
Style React Components: 7 Ways Compared - SitePoint
Props can be used to style styled components in the same way that they ... I had a bit of a struggle with...
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