innerRef is leaked as a prop to the wrapped component
See original GitHub issueVersion
1.4.4
Reproduction
https://www.webpackbin.com/bins/-KfSW7ArY2ALUjC5qswH
Steps to reproduce
Wrap any component in styled()
and use the innerRef
callback to access it.
Expected Behavior
innerRef
should not be leaked as a prop to the wrapped child component.
Actual Behavior
innerRef
is leaked as a prop to the wrapped child component.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Handle ref props with Higher Order Components - Egghead.io
We will pass the ref as an innerRef prop so that the Higher Order Component can re-assign the ref to the component that...
Read more >How to Use React Refs - Ross Bulat - Medium
Take a look at the following example, where we pass our forwarded ref down to the wrapped class component as an innerRef prop:...
Read more >Releases - styled-components
Styled Components Releases. ... Adjust innerRef deprecation warning to not be fired if wrapping a custom component, ... SSR memory leaks? No more!...
Read more >Memory leaks on React Component - Stack Overflow
I am new to React and am faced with a memory leak issue and I can't figure out ... styles"; function Sidebar(props) {...
Read more >styled-components | Yarn - Package Manager
Because styled-components allows any kind of prop to be used for styling (a trait shared by most CSS-in-JS libraries, but not the third...
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
I’m not misunderstanding, I get what you’re trying to tell me: Don’t pass
innerRef
to wrapper child components.I think what you’re misunderstanding is that this would make some things impossible. Imagine this component:
Now when I render it, how can I focus the input?
(I don’t know if this is actually the case, but I think it is)
You can fix this with
innerRef
though:I think you might be misunderstanding what the issue is.
innerRef is an ok pattern to use to access the wrapped child, but in that styled wrapper component it should be deleting the innerRef prop and not forwarding it to the child. That’s what I’m trying to point out. innerRef is a styled-components implementation detail that shouldn’t be leaked.