Skip to content

[styled-components] Support shouldForwardProp option #43693

Closed

Description

@resir014

The latest version of styled-components, 5.1.0, has added support for shouldForwardProp, which works slightly different than in emotion:

const Comp = styled('div').withConfig({
  shouldForwardProp: (prop, defaultValidatorFn) => !['filterThis'].includes(prop),
})`
  color: red;
`;

render(<Comp filterThis="abc" passThru="def" />);

// Renders: <div className="[generated]" passThru="def"></div>

Activity

  1. mattfwood commented on Apr 7, 2020

    @mattfwood

    Is there a way to force Typescript to allow this in the meantime?

    EDIT: This worked well enough for now:

    // @ts-ignore
    export const Box = styled('div').withConfig({
      shouldForwardProp: (prop) => shouldForwardProp(prop)
    })({
      boxSizing: 'border-box',
      minWidth: 0
    }, systemProps)
  2. danilofuchs commented on Apr 7, 2020

    @danilofuchs
    Contributor

    I would be happy to try to provide the new types for @types/styled-components. I will open a branch in my fork so you can take a look.

  3. danilofuchs commented on Apr 7, 2020

    @danilofuchs
    Contributor

    Please check my PR: #43718

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions