question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

button: ref isn't passed onto base button element

See original GitHub issue

Bug

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

  1. Set ref on the Button component with a callback.
  2. 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jaketrentcommented, Oct 19, 2017

@bressain innerRef should work as before now in button@9.0.3 . Please give it a try and let me know.

0reactions
bressaincommented, Oct 23, 2017

Looks like it’s working again, thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found