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!

Answer from dropbeardan on Stack Overflow
🌐
styled-components
styled-components.com › docs › basics
Styled Components Basic
As you can see, we get access to our newly created props in the interpolations, and the type attribute is passed down to the element. Notice that when wrapping styled components, .attrs are applied from the innermost styled component to the outermost styled component.
🌐
styled-components
styled-components.com
styled-components
Here we're saying that when the $primary property is set we want to add some more css to our component, in this case change the background and color. That's all, we're done! Take a look at our finished component: const Button = styled.button<{ $primary?: boolean; }>` background: transparent; border-radius: 3px; border: 2px solid #BF4F74; color: #BF4F74; margin: 0.5em 1em; padding: 0.25em 1em; ${props => props.$primary && css` background: #BF4F74; color: white; `} `; const Container = styled.div` text-align: center; ` render( <Container> <Button>Normal Button</Button> <Button $primary>Primary Button</Button> </Container> );
Discussions

When you are working with Styled Components, do you use this?
The #1 point of Styled Components is for creating reusable styles. I'd be interested in your thought process of not thinking this is a time to use it? const Flexed = styled.div` display: flex; justify-content: space-between; align-items: center; ` More on reddit.com
🌐 r/reactjs
24
13
September 26, 2022
How do I provide props to styled elements in Typescript?
I looked at the docs and other than creating a whole empty component purely for providing a definition of props I'm not sure of if it's possible to provide custom props to a styled element ... More on github.com
🌐 github.com
100
March 30, 2017
Using styled-components with props and TypeScript
I'm trying to integrate TypeScript into our project and so far I stumbled upon one issue with styled-components library. Consider this component import * as React from "react"; import sty... More on stackoverflow.com
🌐 stackoverflow.com
Feature Request: Option to pass "as" prop down to wrapped component when using styled(Comp)
But as we know the devil's in the details, and so I noticed during migration to v4 that there's an important difference between letting a Base component handle the as prop and using s-c's own prop: The first styled component to receive the as prop uses it directly, and there's no way other ... More on github.com
🌐 github.com
27
October 19, 2018
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)}%;
`;
🌐
Emotion
emotion.sh › docs › styled
Emotion – Styled Components
You can create dynamic styles that are based on props and use them in styles. ... To use styles from a styled component but change the element that's rendered, you can use the as prop.
🌐
DEV Community
dev.to › elijahtrillionz › complete-guide-on-how-to-use-styled-components-in-react-360c
Complete Guide On How To Use Styled-components In React - DEV Community
February 19, 2022 - We could have multiple functions - as many as needed in the component. const Button = styled.button` padding: 10px; background: ${(props) => (props.active ?
🌐
MUI
mui.com › system › styled
styled() - MUI System
If you inspect this element with the browser DevTools in development mode, you will notice that the class of the component now ends with the MyThemeComponent-root, which comes from the name and slot options that were provided. In addition to this, the color, sx, and variant props are not propagated to the generated div element. If you would like to remove some of the MUI System specific features, you can do it like this: const StyledComponent = styled('div', {}, { name: 'MuiStyled', slot: 'Root', - overridesResolver: (props, styles) => styles.root, // disables theme.components[name].styleOverrides + skipVariantsResolver: true, // disables theme.components[name].variants + skipSx: true, // disables the sx prop }); CopyCopied(or $keyC)
🌐
LogRocket
blog.logrocket.com › home › 8 awesome features of styled-components
8 awesome features of styled-components - LogRocket Blog
June 4, 2024 - const InheritedDiv = styled(Div)` ... border: 1px solid palevioletred; Props can be passed to styled components just as they are with regular React components (class or functional)....
Find elsewhere
🌐
DEV Community
dev.to › britotiagos › using-props-on-styled-component-and-nextjs-51lk
Using props on styled-component and next.js - DEV Community
March 3, 2022 - ${(props) => props.secondary && ` background: #f00; color: #00a8; border-radius: 0 `}; ... Some people will find this a bit too hard to read, but if you have the correct format or styles in your code editor it will become easy to read.
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › understanding transient props in styled‑components
Understanding Transient Props in styled‑components, by John Kavanagh
October 28, 2025 - Transient props are quite simply props which have been prefixed with a dollar sign ($). styled‑components uses this prefix to avoid forwarding the prop to the DOM element beneath. These were introduced in v5.1.0 of styled‑components, since May 2020.
🌐
Medium
jakemccambley.medium.com › transient-props-in-styled-components-3105f16cb91f
Transient Props in styled-components | by Jake McCambley | Medium
November 4, 2021 - Overview: Transient Props allow you to pass boolean value props to styled-components such that they do not render as an element’s attributes on the DOM.
🌐
Smashing Magazine
smashingmagazine.com › 2020 › 07 › styled-components-react
How To Use Styled-Components In React — Smashing Magazine
July 23, 2020 - Styled components can differentiate between the types of props they receive. They know that type is an HTML attribute, so they actually render <button type="button">Button A</button>, while using the bg prop in their own processing.
🌐
Reddit
reddit.com › r/reactjs › when you are working with styled components, do you use this?
r/reactjs on Reddit: When you are working with Styled Components, do you use this?
September 26, 2022 -

I'm doing a project from my job and here we use Styled Components to do all the components. I`m trying to implement new approaches to do a clean code without repetition. I have a lot of div's with the code bellow. So I have this question, in this case, when I have the same code from a simple flex div, makes sense set the style directly on a div or it is better create a component with this?

What is the personal rule for you guys to create a new component with styled components?

<div style={{display: 'flex'**,** justifyContent: 'space-between'**,** alignItems: 'center'}}>

🌐
GitHub
github.com › RafalFilipek › styled-props
GitHub - RafalFilipek/styled-props: Simple lib that allows you to set styled props in your styled-components without stress.
November 25, 2019 - As you can see each prop can be mapped into specific value for selected css rule. If you need another combination, you just add it in styles.js. Everything is based on props. As we know in React you can set defaultProps for each component. You can also use them to set default values for styles.
Starred by 241 users
Forked by 9 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
DEV Community
dev.to › sarahscode › props-are-not-forever-preventing-props-from-being-passed-to-the-dom-with-styled-components-v5-1-l47
Props Are Not Forever: Preventing Props From Being Passed to the DOM with styled-components v5.1 - DEV Community
November 23, 2020 - We have a number of components in our design system that receive props used exclusively for styling, and I'm hoping to get a chance to take a deeper look at these components and see if we can use the shouldForwardProp config to minimize the props we pass through to the DOM. Transient props are props that don't get passed to the DOM. Similar to shouldForwardProp, this is a way for styled-components to know that a prop is only used for styling and should not make its way to the DOM.
🌐
Medium
byrayray.medium.com › how-to-add-props-to-styled-components-in-react-js-with-typescript-1df49ef951bf
How To Add Props To Styled Components in React.js with TypeScript | by RayRay | Medium
March 16, 2021 - I define the property state in my interface, and I tell that I accept only the values of the sendState enum. So if I put in another value, my IDE and build system starts complaining. TypeScript helps me write predictable code, as you can see. You usually define a styled-component like: export const StatusMessage = styled.div this.
🌐
GitHub
github.com › styled-components › styled-components › issues › 630
How do I provide props to styled elements in Typescript? · Issue #630 · styled-components/styled-components
March 30, 2017 - I looked at the docs and other than creating a whole empty component purely for providing a definition of props I'm not sure of if it's possible to provide custom props to a styled element other than theme. Example For the above example ...
Author   tal
🌐
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.
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 91.2% | JavaScript 8.6%
🌐
GitHub
github.com › styled-components › styled-components › issues › 2129
Feature Request: Option to pass "as" prop down to wrapped component when using styled(Comp) · Issue #2129 · styled-components/styled-components
October 19, 2018 - This used to work with the Base component, but breaks with sc's 'as' prop, since as="a" effectively changes the above component definition to const CustomNavBarTab = styled('a'), disregarding all of NavBarTab's styles & behaviour.
Author   diondiondion
🌐
Robin Wieruch
robinwieruch.de › styled-components
Styled Components Best Practices - Robin Wieruch
April 11, 2021 - Next we want to use transient props with styled components, because they benefit us twofold: First, it marks the prop as only consumable by the styled component and thus the prop will not be passed to the HTML element as attribute.