import styled from "styled-components/native"
const Pressable = styled.Pressable(props => (props.buttonStyle))

export default function App() {
  return (
    <View style={styles.container}>
      <Pressable buttonStyle={{ backgroundColor: "pink" }}>
        <Text>This is button</Text>
      </Pressable>
    </View>
  );
}
Answer from Inder on Stack Overflow
🌐
styled-components
styled-components.com › docs › basics
Styled Components Basic
The styled method works perfectly on all of your own or any third-party component, as long as they attach the passed className prop to a DOM element. ... If you are using react-native keep in mind to use style instead of className.
🌐
GitHub
github.com › styled-components › styled-components
GitHub - styled-components/styled-components: Fast, expressive styling for React. Server components, client components, streaming SSR, React Native—one API.
Server components, client components, streaming SSR, and React Native—same API, automatic runtime detection. Full CSS, no compromises. Media queries, pseudo-selectors, nesting, keyframes, global styles. If CSS supports it, so does styled-components. TypeScript-first. Built-in types ship with the package. Props flow through to your styles with full inference—no @types install, no manual generics.
Starred by 41K users
Forked by 2.5K users
Languages   TypeScript 88.7% | JavaScript 10.9% | HTML 0.4%
Discussions

React Native Styled Components how to pass non specific styles as props for re usable components
I would like to create a reusable component which takes in style props while still using styled components. Normally using the vanilla react native styles, this is really simple one would just pass in the style object as a prop an use it as a value in the necessary component. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - How to setup styled-components' "css prop" in a React Native + Typescript project? - Stack Overflow
I tried also import {} from 'styled-components/cssprop'; but it generated an error: styled-components/cssprop could not be found within the project. This got me in a good place where I can use the css property on any React component and it gets properly applied as style. More on stackoverflow.com
🌐 stackoverflow.com
Dynamically Styled Button in React Native using Styled Components - Stack Overflow
Below, I've created a Button component similar to the Adapting based on props example found in the styled-component docs. import React from 'react'; import { Text, TouchableHighlight } from 'react-native'; import styled from 'styled-components/native'; const colors = { accent: '#911', highlight: ... More on stackoverflow.com
🌐 stackoverflow.com
November 4, 2017
React — Passing props with styled-components
I just read in the styled-components documentation that the following is wrong and it will affect render times. If that is the case, how can I refactor the code and use the required props to create a dynamic style? Thank you in advance. ... import React from 'react' import styled from ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
rossbulat.medium.com › how-to-use-styled-components-in-react-native-3543c97cb485
How to Use Styled Components in React Native | by Ross Bulat | Medium
July 14, 2020 - Styled Components in React Native actually relies on the css-to-react-native package to convert CSS from a styled component to a recognisable Stylesheet object for React Native to handle.
🌐
Jasonkang14
jasonkang14.github.io › react-native › how-to-set-up-styled-component
React Native with Styled Component - Blog by Jason Kang
In order to apply styled-components for your React Native project, you have to import your components from styled-components/native like below; import styled from "styled-components/native"; const StyledView = styled.View` ${(props) => props.class === "mainOtherText" && ` padding-top: 104 ...
🌐
styled-components
styled-components.com › docs › api
styled-components
It uses the render prop pattern to allow for dynamic access to the theme during rendering. It passes the current theme (based on a ThemeProvider higher in your component tree) as an argument to the child function. From this function, you may return further JSX or nothing. import { ThemeConsumer ...
🌐
Educative
educative.io › answers › how-to-use-styled-components-with-react-native
How to use styled components with React Native
According to the styled-component documentation, you can pass a function (“interpolations”) to a styled component’s template literal to adapt it based on its props. This means that you can give a component a primary state which is set to true when passed, ... Styled React Native.
Find elsewhere
🌐
Smashing Magazine
smashingmagazine.com › 2020 › 07 › styled-components-react
How To Use Styled-Components In React — Smashing Magazine
July 23, 2020 - Notice how we don’t need a ternary when setting the width? That’s because we’ve already set a default for it with width: props.width || "100%",. Also, we used CSS custom properties because we can! Note: If styled components are React components, and we can pass props, then can we also use states?
🌐
LogRocket
blog.logrocket.com › home › how to use styled-components with react native
How to use styled-components with React Native - LogRocket Blog
June 4, 2024 - React Native allows us to define values for properties like margin, padding, shadows, font size, and more by defining without a unit such as px (pixels). For example, the font size when using StyleSheet API is defined as fontSize: 20;. These unitless values render differently on various screen sizes due to the pixel density of a particular screen. When using styled-components, however, you have to use the suffix px when defining the value of a property like font-size because styled-components uses css-to-react-native.
🌐
Stack Overflow
stackoverflow.com › questions › 69243951 › how-to-setup-styled-components-css-prop-in-a-react-native-typescript-projec
reactjs - How to setup styled-components' "css prop" in a React Native + Typescript project? - Stack Overflow
import type {Interpolation} from 'styled-components'; import theme from './theme'; type ThemeType = typeof theme; // Types for styled.COMPONENT declare module 'styled-components/native' { export interface DefaultTheme extends ThemeType {} } // Types for Css prop declare module 'styled-components' { export interface DefaultTheme extends ThemeType {} } declare module 'react' { interface Attributes { css?: Interpolation<ThemeType>; } }
🌐
GitHub
github.com › styled-components › styled-components › issues › 4165
6.0.8 breaks typing of custom props with React Native · Issue #4165 · styled-components/styled-components
September 14, 2023 - import React from "react"; import styled from "styled-components/native"; interface Props { customProp?: string; secondProp?: string; } const StyledView = styled.View<Props>` ${(props) => { // correctly typed props.customProp; // correctly typed props.secondProp; return null; }} `; const Component = () => ( <StyledView // No overload matches this call.
🌐
React Native
reactnative.dev › docs › style
Style · React Native
February 20, 2026 - All of the core components accept a prop named style. The style names and values usually match how CSS works on the web, except names are written using camel casing, e.g. backgroundColor rather than background-color.
🌐
OpenReplay
blog.openreplay.com › theming-react-native-applications-with-styled-components
Theming React Native Applications with Styled Components
March 2, 2022 - In the example above, we create a styled component Container that wraps the react-native SafeAreaView component. We can also pass the components’ props and other valid JavaScript code as the styles are wrapped in template literals as you can see in the following example:
Top answer
1 of 1
8

Here you have:

const Button = (props) => {
    return (
        <ButtonContainer underlayColor={colors.highlight}>
            <Label>
                {props.children}
            </Label>
        </ButtonContainer>
    );
};

If ButtonContainer was a normal React component, you wouldn't expect the props passed to Button to be automatically passed to ButtonContainer. You'll have to do <ButtonContainer underlayColor={colors.highlight} {...props} /> to do it.

Actually ButtonContainer is a normal React component, the only difference is you pre-apply some styles using an HOC.

Also if you desugar this to a React.createElement call, you can see there's no way props can be passed automatically, because a Function's arguments don't get passed automatically to the function calls inside it.

const Button = (props) => {
    return React.createElement(ButtonContainer, { underlayColor: colors.highlight }, ...);
};

It's nothing specific to styled-components. You just have to pass down the props yourself to ButtonContainer, as well as to Label.

So you'd rewrite your code to:

const Button = (props) => {
    return (
        <ButtonContainer underlayColor={colors.highlight} onPress={props.onPress} outline={props.outline}>
            <Label outline={props.outline}>
                {props.children}
            </Label>
        </ButtonContainer>
    );
};

Technically a React component can pass down props to it's children, so ButtonContainer could pass them down to Label using React.Children and React.cloneElement APIs. But ButtonContainer doesn't do that for obvious reasons, e.g. you'd not want underlayColor and onPress to be passed to Label automatically. It would cause a lot of confusing bugs.

🌐
DEV Community
dev.to › amanhimself › using-styled-components-with-react-native-4k15
Using Styled Components with React Native - DEV Community
July 5, 2019 - Inside this file we are going to create a custom button that requires props such as backgroundColor, textColor and the text itself for the button. You are going to use TouchableOpacity and Text to create this custom button but without importing react-native library using a functional component CustomButton. import React from 'react'; import styled from 'styled-components'; const CustomButton = props => ( <ButtonContainer onPress={() => alert('Hi!')} backgroundColor={props.backgroundColor} > <ButtonText textColor={props.textColor}>{props.text}</ButtonText> </ButtonContainer> ); export default CustomButton; const ButtonContainer = styled.TouchableOpacity` width: 100px; height: 40px padding: 12px; border-radius: 10px; background-color: ${props => props.backgroundColor}; `; const ButtonText = styled.Text` font-size: 15px; color: ${props => props.textColor}; text-align: center; `;
🌐
LogRocket
blog.logrocket.com › home › building react native applications with styled system
Building React Native applications with Styled System - LogRocket Blog
June 4, 2024 - By creating reusable components with Styled System, we have provided each component with access to the necessary style props passed to it by the style functions. Consequently, we can easily build our layout by using these props to manipulate the display of the component. When compared with React Native style objects, our code is easier to read and maintain.
🌐
Medium
medium.com › building-with-react-native › why-i-like-using-styled-components-in-react-native-apps-1x10-6f98a46efdf9
Why I like using Styled Components in React Native apps — 1x10 | by Tasos Maroudas | Building With React Native | Medium
December 17, 2019 - An app has to look nice as well! And it’s not a pleasant task for all JavaScript/FrontEnd devs; especially when someone has just started with web development. This is where styled components come and save the day, by making styling simpler specifically for React Native apps in my opinion.
Top answer
1 of 7
76

I believe what the documentation is saying is that you should avoid including your styles inside of the rendering component:

DO THIS

const StyledWrapper = styled.div`
  /* ... */
`

const Wrapper = ({ message }) => {
  return <StyledWrapper>{message}</StyledWrapper>
}

INSTEAD OF THIS

const Wrapper = ({ message }) => {
  // WARNING: THIS IS VERY VERY BAD AND SLOW, DO NOT DO THIS!!!
  const StyledWrapper = styled.div`
    /* ... */
  `

  return <StyledWrapper>{message}</StyledWrapper>
}

Because what happens is when the component's Props changes, then the component will re-render and the style will regenerate. Therefore it makes sense to keep it separate.

So if you read further on to the Adapting based on props section, they explain this:

const Button = styled.button`
  /* Adapt the colours based on primary prop */
  background: ${props => props.primary ? "palevioletred" : "white"};
  color: ${props => props.primary ? "white" : "palevioletred"};

  font-size: 1em;
  margin: 1em;
  padding: 0.25em 1em;
  border: 2px solid palevioletred;
  border-radius: 3px;
`;

// class X extends React.Component {
//  ...

render(
  <div>
    <Button>Normal</Button>
    <Button primary>Primary</Button>
  </div>
);

// }

this works because when you use the Button component in class X, it will know the props of class X without you having to tell it anything.

For your scenario, I imagine the solution would be simply:

const TabWrapper = styled.li`
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 100px;
  margin: 1px;
  font-size: 3em;
  color: ${props => (props.isSelected ? `white` : `black`)};
  background-color: ${props => (props.isSelected ? `black` : `#C4C4C4`)};
  cursor: ${props => (props.isSelected ? 'default' : `pointer`)};
`;

const Tab = ({ onClick, isSelected, children }) => {
  return <TabWrapper onClick={onClick}>{children}</TabWrapper>
}

const X = <Tab onClick={() => console.log('clicked')} isSelected>Some Children</Tab>

I haven't tested this at all, so please feel free to try it out and let me know if it works for you or whatever worked for you!

2 of 7
57

You can pass an argument with Typescript as follows:

<StyledPaper open={open} />    

...

const StyledPaper = styled(Paper)<{ open: boolean }>`
   top: ${p => (p.open ? 0 : 100)}%;
`;
🌐
Scalablecss
scalablecss.com › styled-components-quickstart-guide
How To Use Styled-Components In React: A Quick Start Guide - Scalable CSS
Congratulations, you just built ... secondary, danger, etc). Styled Components have an elegant solution for this, where you leverage props to make your component styles dynamic....