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
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.
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)}%;
`;
Discussions

`as` prop of styled components in TypeScript
When using the styled component pass the as prop from Emotion 10 to change the element being used. More on github.com
🌐 github.com
18
December 28, 2018
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
🌐
Emotion
emotion.sh › docs › styled
Emotion – Styled Components
styled is very similar to css except you call it with an html tag or React component and then call that with a template literal for string styles or a regular function call for object styles. ... Any interpolations or arguments that are functions in styled are called with props, this allows ...
🌐
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 ?
🌐
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.
🌐
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.
Find elsewhere
🌐
MUI
mui.com › system › styled
styled() - MUI System
styles (object | ({ ...props, theme }) => object [optional]): A styles object or a function returning a styles object. The function receives the theme and component's props in an object which is its single argument.
🌐
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.
🌐
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.
🌐
Escuela Frontend
escuelafrontend.com › styled-components-en-react
Cómo Utilizar Styled Components en React
September 20, 2022 - Los tratas igual que a los componentes que ya conoces por lo que puedes pasar props, poner componentes dentro de otros componentes, darle un id, ser reutilizados, entre otras. Para dar estilo puedes usar CSS y otras funcionalidades adicionales ...
🌐
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 - 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.
🌐
DEV Community
dev.to › faraib › dynamic-styling-with-props-in-styled-components-2p7k
Dynamic Styling with Props in Styled-Components - DEV Community
July 15, 2025 - As previously mentioned, the aim is to conditionally render the button based on the state prop, and we do this by using the logical AND operator( && ), where if the state prop is truthy, the expression evaluates to the CSS string inside of the ...
🌐
Reddit
reddit.com › r/typescript › what is the type of the styled-components props in typescript?
r/typescript on Reddit: What is the type of the styled-components props in TypeScript?
January 14, 2023 -

I am trying to do this:

import React from 'react'
import styled, { CSSProperties, useTheme } from 'styled-components'
import { Theme } from './styles'
import useProps from './useProps'

export type BasicInputPropsType<T> = T | Array<T>

export type FactoryStyledPropsType = {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  styledProps: any
}

export type InputPropsFunctionType<I, T> = (props: I) => T

export type InputPropsType<T, I> = T extends Function
  ? InputPropsFunctionType<I, T>
  : T

export default function FactoryFactory<T>(
  as: string,
  serializer: (theme: Theme, props: T) => CSSProperties,
) {
  return function Factory<I>(inputProps: InputPropsType<T, I>) {
    const isPropsFunction = typeof inputProps === 'function'
    const Styled = styled.div<FactoryStyledPropsType>(
      props => props.styledProps,
    )

    function Component(props: I) {
      const actualProps = isPropsFunction
        ? (inputProps as InputPropsFunctionType<I, T>)(props)
        : props
      const theme = useTheme()

      const { styledProps, elementProps } = useProps(
        actualProps,
        theme,
        serializer,
      )

      return (
        <Styled
          {...elementProps}
          styledProps={styledProps}
        />
      )
    }

    Component.toString = Styled.toString

    return Component
  }
}

Essentially that styledProps, it should return what the styled component expects, but I can't figure out how to type it. I am looking at this type definition:

export interface ThemedStyledFunctionBase<
    C extends keyof JSX.IntrinsicElements | React.ComponentType<any>,
    T extends object,
    O extends object = {},
    A extends keyof any = never
> {
    (first: TemplateStringsArray): StyledComponent<C, T, O, A>;
    (
        first:
            | TemplateStringsArray
            | CSSObject
            | InterpolationFunction<ThemedStyledProps<StyledComponentPropsWithRef<C> & O, T>>,
        ...rest: Array<Interpolation<ThemedStyledProps<StyledComponentPropsWithRef<C> & O, T>>>
    ): StyledComponent<C, T, O, A>;
    <U extends object>(
        first:
            | TemplateStringsArray
            | CSSObject
            | InterpolationFunction<ThemedStyledProps<StyledComponentPropsWithRef<C> & O & U, T>>,
        ...rest: Array<Interpolation<ThemedStyledProps<StyledComponentPropsWithRef<C> & O & U, T>>>
    ): StyledComponent<C, T, O & U, A>;
}

But that is way too complex, I am not sure what to do. What is the type I need to specify for my styledProps?

🌐
GitHub
github.com › emotion-js › emotion › issues › 1137
`as` prop of styled components in TypeScript · Issue #1137 · emotion-js/emotion
December 28, 2018 - // Custom styled function that is typed with my theme interface import styled, { CreateStyled } from '@emotion/styled' import { ITheme } from '../theme' export default styled as CreateStyled<ITheme> // Style function interface in a Util module declare module 'Util' { import { css } from '@emotion/core' import { ITheme } from '../util/theme' type CssType = typeof css export interface IStyleFunction<P = {}> { ( arg0: { theme: ITheme } & P): ReturnType<CssType> | false | null } } // Component code type HeadingProps = { size?: FontSizes } const baseStyles: IStyleFunction<HeadingProps> = ({ theme }
Author   felixjung
🌐
Panda-css
panda-css.com › docs › concepts › style-props
Style props | Panda CSS - Panda CSS
Style props are just CSS properties that you can pass to your components as props.
🌐
YouTube
youtube.com › watch
React Styled Components - 4 - Using Props - YouTube
📘 Courses - https://learn.codevolution.dev/💖 Support UPI - https://support.codevolution.dev/💖 Support PayPal - https://www.paypal.me/Codevolution💾 Github...
Published   November 23, 2021
🌐
YouTube
youtube.com › pedrotech
🚀 Passing Props To Styled Components - ReactJS Beginner Course | Tutorial #13 - YouTube
This is the series where I teach ReactJS for beginners. We will be covering interesting topics such as reusable components (class/functional), states, hooks,...
Published   August 22, 2020
Views   13K
🌐
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'}}>