You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to disable the automatic pass down of props so we don't have that warning anymore?
Thanks!
Reacted by Haroen Viaene, I'm Luis! ^-^, Emil Kjær Eriksen, Janne Annala, ixcviw7bw, Damiano Salvi, César Guadarrama, Debajit, Joe, Kewin Dousse and 1 more
Reacted by Max Stoiber, Jordan Rooks, Daniel Steigerwald, Haz, Dariusz Rzepka, Thomas Obermüller, sk22, Kostia Vyrodov, Hai Nguyen, Ivan Gerasimov and 118 more
Reacted by Janne Annala, Josh Balfour, Zachary Raineri, Alexander Kim, Wicus Pretorius, Richard Lopes, Nick Artemov, Gonzalo D'Elia, Alexis Patiño, Mike Wolf and 3 more
Reacted by sk22, Kostia Vyrodov, Tan Duong, Vincent M. van der Meulen, Stephen Langdon, S_10 M, nupurgrover, Roman Kuleshov, Vad_Siam, neaucode and 2 more
Reacted by Kostia Vyrodov, Tan Duong, Gustavo Pitombo, Gabriel Bieules, Henrik Haugbølle, Vincent M. van der Meulen, Paul Chobert, Nico Hauser, Stephen Langdon, S_10 M and 16 more
Reacted by Kostia Vyrodov, Seiji Takahashi, Vanessa Pacheco, Vincent M. van der Meulen, Michael D, Stephen Langdon, Alex Kinnee, nupurgrover, Javier Candalaft, Rafał Kwaśniewski and 13 more
Reacted by neaucode, Robert Molina, Andy Mardell, Lucas Vogel and Peter Brecska
Reacted by neaucode, Kasey Cowley, Damiano Salvi, Jonathan Solis, Irek Nazmiev and Marie Hooper
Ah yeah, true – I think this is actually expected behaviour here, you're right! I'll close this for now since @vdanchenkov's solution works fine and we can't really do anything from our side to fix this. Cheers!
works fine (although the syntax highlighting is broken on vscode). However it creates an anonymous component that makes it harder to navigate in the virtual DOM and read a stacktrace. Naming the component is much more verbose and does not solve the indent in the virtual DOM so I would support an option to intercept props.
With a very naïve approach I would like to be able to write something like:
Reacted by Nguyen Maxime, Philipp Sporrer, Jeremy Dunn, Michael DePetrillo, Carter Wooten, BraveDev, Joe, Christian Jensen, mike douges, Enix and 34 more
Reacted by Laurent Ros, Justin Smith, Janosh Riebesell, ManAnRuck, Albert, Duongasaur and alexpaxton
I'm facing this problem too. I don't think const ListElement = styled(({ active, ...rest }) => <Link {...rest} />) is bullet proof solution. Here is where it is failing for me:
1) Callers can pass as prop and now the component suddenly breaks. for example:
<ListElement as="span" />
One would expect that it would render a Link as a span tag, but it gets rid of the Link altogether. Don't get me wrong, this is the expected behavior in styled-components, but it makes it difficult customize things. I had to introduce a tagName prop just for that. And I keep getting the question why you need "tagName" since styled-components has "as" prop?
2) Hard, if not impossible to extend styles.
I have a Box component with some styles. This Box has a color prop that I need to exclude (otherwise it will bleed). Now I want a Flex component that augments this Box with flexbox capabilities. This Flex has a direction prop that I need to exclude. For example:
Now if you inspect the DOM Box color does not bleed, but Flex direction does. I'm failing to identify how to properly extend these styles.
3) Having to deal with forwardRef and increasing the React DOM Tree.
Since I'm adding ({ active, ...rest }) => <Link {...rest} /> forward refs don't work anymore. Meaning <ListElement ref={React.createRef()} />the ref will be the React element instead of the actual DOM, forcing me to use a deprecated findDOMNode API. Or wire the forwardRef which increases the React Depth Tree (which brings performance issues in React dev env)
I feel that everything would be much easier if styled-component allowed an API to exclude props to bleed to the DOM:
Reacted by Lancelot Prigent, Ahmed Abdel-Aziz, Roman Komarov, Levin Rickert, Sultan Arziyev, unioncodev, Joe, Adam Drago, Dave Ackerman, powderham and 77 more
Reacted by António Santos, Albert, Marco Wettstein, neaucode, avernikoz and Marouane R
@tomspeak and anyone else... here is an example of how it could be bypassed as an issue. Although this solution would be very hard to get a team to understand and stick too. codesandbox example!
Skipping the filter array will just gracefully work. I guess the ideal solution in the future would just allow the second parameter to be used for filtering as others have already suggested in the thread above.
Reacted by Joachim Seminck, Alex Holachek, Karthick Ramakrishnan and Ankit Shah
I don't think this issue should be closed. I'm very much still running into this issue, and it seems unfortunate that the proper way to avoid this problem is to add a wrapper component.
Reacted by Luke Tanner, Marco Souza, Dara Clare Carolan and ffind
@alansouzatiexcludeProps makes me think that the prop will not be available, so, when writing out the CSS my expectation is that it's not there for our use. How about captureProps instead?
Activity
vdanchenkov commentedon Oct 25, 2016
Do you mean some props selectively? I'd suggest:
timsuchanek commentedon Oct 25, 2016
Yes indeed. Nice solution, thanks!
timsuchanek commentedon Oct 26, 2016
As we are using typescript and it doesn't yet support the spread operator in objects, thats my solution right now:
@mxstbr Maybe we should write an official statement into the docs as other people could encounter a similiar problem with the new react version?
mxstbr commentedon Oct 30, 2016
Hmm, that's an issue with out
validAttrs.jsutil – it seems to let that one pass through, even though it's invalid.vdanchenkov commentedon Oct 31, 2016
@mxstbr This issue is about styling 3-rd party components. I believe that you want to pass all the props unfiltered in this case.
mxstbr commentedon Oct 31, 2016
Ah yeah, true – I think this is actually expected behaviour here, you're right! I'll close this for now since @vdanchenkov's solution works fine and we can't really do anything from our side to fix this. Cheers!
iamthesiz commentedon Sep 26, 2017
I did mine like this.
joetidee commentedon Apr 28, 2018
What about if you are extending a component? In the example below, I want
completedto be accessed byStyledItemTextareabut notTextarea.nicgirault commentedon Jun 27, 2018
works fine (although the syntax highlighting is broken on vscode). However it creates an anonymous component that makes it harder to navigate in the virtual DOM and read a stacktrace. Naming the component is much more verbose and does not solve the indent in the virtual DOM so I would support an option to intercept props.
With a very naïve approach I would like to be able to write something like:
janosh commentedon Jan 4, 2019
Any comments from maintainers regarding @nicgirault's proposal? Something along those lines would be nice to have!
alansouzati commentedon Jan 18, 2019
I'm facing this problem too. I don't think
const ListElement = styled(({ active, ...rest }) => <Link {...rest} />)is bullet proof solution. Here is where it is failing for me:1) Callers can pass
asprop and now the component suddenly breaks. for example:One would expect that it would render a
Linkas a span tag, but it gets rid of the Link altogether. Don't get me wrong, this is the expected behavior in styled-components, but it makes it difficult customize things. I had to introduce atagNameprop just for that. And I keep getting the question why you need "tagName" since styled-components has "as" prop?2) Hard, if not impossible to extend styles.
I have a Box component with some styles. This Box has a
colorprop that I need to exclude (otherwise it will bleed). Now I want a Flex component that augments this Box with flexbox capabilities. ThisFlexhas adirectionprop that I need to exclude. For example:Now if you inspect the DOM Box color does not bleed, but Flex direction does. I'm failing to identify how to properly extend these styles.
3) Having to deal with forwardRef and increasing the React DOM Tree.
Since I'm adding
({ active, ...rest }) => <Link {...rest} />forward refs don't work anymore. Meaning<ListElement ref={React.createRef()} />the ref will be the React element instead of the actual DOM, forcing me to use a deprecatedfindDOMNodeAPI. Or wire the forwardRef which increases the React Depth Tree (which brings performance issues in React dev env)I feel that everything would be much easier if styled-component allowed an API to exclude props to bleed to the DOM:
5 remaining items
JamesBliss commentedon Apr 17, 2019
@tomspeak I've found these:
A v5 Roadmap #1934 which links to issue #2093 but nothing still seems defined, decided or clear.
JamesBliss commentedon Apr 17, 2019
@tomspeak and anyone else... here is an example of how it could be bypassed as an issue. Although this solution would be very hard to get a team to understand and stick too. codesandbox example!
rtymchyk commentedon Apr 18, 2019
This is very annoying when trying to make components with AMP :)
Alappin commentedon Apr 22, 2019
A temporary clean work around.
Skipping the filter array will just gracefully work. I guess the ideal solution in the future would just allow the second parameter to be used for filtering as others have already suggested in the thread above.
nkov commentedon May 8, 2019
Another workaround is to use
data-*attributes, for which the DOM doesn't throw warnings.nathggns commentedon Jul 31, 2019
I don't think this issue should be closed. I'm very much still running into this issue, and it seems unfortunate that the proper way to avoid this problem is to add a wrapper component.
Zerquix18 commentedon Aug 8, 2019
+1 ??
jdfm commentedon Aug 12, 2019
@alansouzati
excludePropsmakes me think that the prop will not be available, so, when writing out the CSS my expectation is that it's not there for our use. How aboutcapturePropsinstead?rtymchyk commentedon Aug 22, 2019
This is good but but
omitis being dropped for performance reasons from Lodash.Here's a variation:
lcswillems commentedon Nov 15, 2019
I have just written an RFC for filtering forwarded props: #2878
Would you like a solution like this?
TL;DR It consists of adding a second parameter for filtering props. The current solution:
is turned into:
This is easy to write and to understand, and props filtering (which is not the important part of the definition) is sent at the end of the definition.
random1911 commentedon Nov 17, 2019
Hey guys.
What about made new API similar to Emotion - https://emotion.sh/docs/styled#customizing-prop-forwarding - that shouldForwardProp really helpfull with damn styling
SimonSomlai commentedon Apr 27, 2020
Here's a simple typescript solution that worked for me;
avxkim commentedon Apr 29, 2020
@SimonSomlai how do you type
<RouteLink />'s children? I'm just getting an error:type '{ children: string; }' has no properties in common with typeankitsny commentedon Aug 27, 2020
You can use transient props, Checkout this docs
https://styled-components.com/docs/api#transient-props
https://styled-components.com/docs/api#shouldforwardprop
jonatassales commentedon Mar 23, 2021
Created a solution based on what @anks333 did:
...