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.

variant prop ignored when passed to custom component

See original GitHub issue

Input

const MyComponent = ({ children, ...props }) =>
  <div {...props}>{children}</div>

const CompWithStyleProp = () =>
  <MyComponent color="red">Works: comp with style prop</MyComponent>

const DivWithVariant = () =>
  <div variant="heading.h3">Works: div with variant</div>

const CompWithVariant = () =>
  <MyComponent variant="heading.h3">Doesn't work: comp with variant</MyComponent>

// render
export default () => (
  <div>
    <CompWithStyleProp/>
    <DivWithVariant/>
    <CompWithVariant/>
  </div>
)

Output

image

Expected output

I expect the third line (CompWithVariant) to be rendered with the heading.h3 variant.

Passing style props to a custom component works as expected. Passing a variant prop to a regular DOM tag (div) works as expected. Passing a variant prop to a custom component does not cause the style to be applied to the rendered output.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shadcncommented, Mar 10, 2021

I’ve been able to reproduce this. Looking into it.

Thanks for filing this bug.

0reactions
ftescommented, Apr 1, 2021

Neat, thanks! I will try this out in the next days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theme UI sx prop ignored when importing a storybook ...
The sx prop isn't passed down to the component, it's in fact converted to CSS and a className is auto-generated and applied to...
Read more >
Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >
Custom props not being passed to react components #1267
The problem Custom props are not being passed to "native" components. React specifies that any lower-case prop will automatically be passed ...
Read more >
How to create visual variants for React components using ...
To select a variant of a component you modify the className prop. You can also pass a number of classes this way and...
Read more >
The List Component - React-admin - Marmelab
Use the aside prop for that, passing the component of your choice: ... You can also pass React elements as children, to build...
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