innerRef does not work as expected
See original GitHub issueAs rightfully pointed out in https://github.com/jxnblk/rebass/issues/72#issuecomment-315534122, since 1.0.0 we should start using innerRef
to get the reference as that’s the way it’s done in styled-components
.
However innerRef
doesn’t actually work as expected. I suspect this has to do with the fact that in src/create-component.js
and src/hoc.js
components are wrapped in a way that innerRef
doesn’t get passed down to the children. Some details about this are explained in here: https://github.com/styled-components/styled-components/issues/927#issuecomment-309140340.
A minimal reproducible test case for this issue can be seen here:
import { Input, Button } from 'rebass'
class InputWrapper extends React.Component {
constructor(props) {
super(props)
this.inputRef = null
}
render() {
return (
<div>
<Input innerRef={ c => this.inputRef = c } />
<Button onClick={() => this.inputRef.focus()}>Focus</Button>
</div>
)
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Error "provided.innerRef has not been ... - Stack Overflow
I'm trying to test a component that has a Draggable from react-beautiful-dnd inside, using react-testing-library and make a snapshot, ...
Read more >API Reference - styled-components
A function that receives the props that are passed into the component and computes a value, that is then going to be merged...
Read more >How to use React's forwardRef function - Felix Gerschau
React's references don't always behave like you would expect them to. In this tutorial, you'll learn why and how you can use the...
Read more >Reusing the `ref` from `forwardRef` with React hooks - ITNEXT
This will work exactly as expected. Honestly, I don't think that it should stay for a while, because the solution is quite big...
Read more >Referencing - React Advanced Form - GitBook
There are two kinds of referencing - component and element references. ... innerRef will not work if the form element is returned by...
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 haven’t been able to get
innerRef
working with 2.0 either yet. However, using the<Ref />
component from Semantic UI React has solved this (at least temporarily) for me.Perhaps a similar helper could be added to Rebass. https://github.com/Semantic-Org/Semantic-UI-React/tree/5a37f2899fcb048a01a6a51d078455f5eb9219df/src/addons/Ref
Closing this since I think #188 addresses this. Please open a new issue if not