How to get ref to the input?
See original GitHub issueI’m using this with material-ui like:
class Amount extends Component {
render() {
return <NumberFormat {...this.props} decimalScale={2} />
}
}
render() {
<TextField
className={classes.textField}
fullWidth={true}
label="Amount"
name="amount"
onChange={this.onAmountChange}
required={true}
InputProps={{
startAdornment: (
<InputAdornment position="start">$</InputAdornment>
),
inputRef: ref => this.trackRef('amount', ref),
inputComponent: Amount
}}
}
But I don’t get a ref to the actual input. How can I get the ref?
Edit: it seem that the omit
help function isn’t copying a ref
function if one is provided
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to get values from input types using this.refs in reactjs?
1. using ref={ inputRef => this.input = inputRef } · 2. this.name.current.focusTextInput()
Read more >Refs and the DOM - React
When a ref is passed to an element in render , a reference to the node becomes accessible at the current attribute of...
Read more >A complete guide to React refs - LogRocket Blog
The first thing we need to do is get a reference for the input: import React, { useRef, useState } from "react"; const...
Read more >Working with refs in React | CSS-Tricks
How to create a ref ... createRef() is a new API that shipped with React 16.3. You can create a ref by calling...
Read more >The Complete Guide to useRef() and Refs in React
To make it work you'll need to create a reference to the input, assign the reference to ref attribute of the tag, and...
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 Free
Top 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
ref
attributes are not passed as props to the component See (https://reactjs.org/warnings/special-props.html). They are internally used by react.I guess in your Amount component you have to manually pass ref . Something like
But in this case as well ref will not forward to actual input. I guess I also have to support something similar
inputRef
like TextField Component.For now, you can use
ReactDOM.findDOMNode(this.amountElm)
to find the actual element if you have passedinputRef: ref => this.amountElm = ref
Whoa! This is awesome, thanks!