Disable automatic passing down of props
See original GitHub issueVersion
1.0.5
Steps to reproduce
import { Link } from 'react-router'
const ListElement = styled(Link)`
${props => props.active && activeListElement}
`
Expected Behavior
Work without warnings
Actual Behavior
Is it possible to disable the automatic pass down of props so we don’t have that warning anymore?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:30 (5 by maintainers)
Top Results From Across the Web
React: Are props objects passed automatically to children ...
If you dont pass the props to the child components, they wont be available to the child component period. Have a look at...
Read more >How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >React Props Cheatsheet: 10 Patterns You Should Know
If you have a lot of props that you're passing down to your component, it may be best to include them on the...
Read more >The Disabled Attribute in React Buttons - Upmostly
Then, we define a function handleClick which uses the selectFruit function passed in props as a callback. We call it with the argument...
Read more >Forwarding Refs - React
We pass our ref down to <FancyButton ref={ref}> by specifying it as a JSX attribute. React passes the ref to the (props, ref)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you mean some props selectively? I’d suggest:
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: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 atagName
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. ThisFlex
has adirection
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 deprecatedfindDOMNode
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: