button: ref isn't passed onto base button element
See original GitHub issueBug
Expected behavior
Probably a borderline “bug”. For situations where you need a ref to the base component element, I would expect that setting the ref
prop would give back an element.
Workaround: Using innerRef
appears to work
Actual behavior
When setting the ref
prop to a function, the resulting element returned is null.
setElement = el => {
// el comes back as null :-(
this.buttonElement = el
}
...
<Button ref={this.setElement}>Ohai!</Button>
Steps to repro
- Set
ref
on theButton
component with a callback. - Run the app and see that the callback is given null.
Related packages
- button@8.0.1
Environment
- OS - MacOS 10.12
- Browser version - Chrome v60
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Accessing button using ref - javascript - Stack Overflow
Button is a component (does not have ref by default) and button is a primitive element (always has ref by default). If you...
Read more >A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >The Button element - HTML: HyperText Markup Language
If the button is a submit button, this Boolean attribute specifies that the form is not to be validated when it is submitted....
Read more >Everything You Need to Know About Refs in React
New and experienced developers alike seem to have trouble with the Refs API. Learn why, how, and when to use Refs in your...
Read more >React Top-Level API
In the above example, React passes a ref given to <FancyButton ref={ref}> element as a second argument to the rendering function inside the...
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
@bressain
innerRef
should work as before now in button@9.0.3 . Please give it a try and let me know.Looks like it’s working again, thanks!