A am using react-rails gem in my ruby on rails project. I try to add reference to my DOM element. This is my component:
class NewItem extends React.Component {
constructor(props) {
super(props);
this.name = React.createRef();
}
handleClick() {
var name = this.name.value;
console.log(name);
}
render() {
return (
<div>
<input ref={this.name} placeholder='Enter the name of the item' />
<button onClick={this.handleClick}>Submit</button>
</div>
);
}
};
When i try to load the page in browser i have this message in console:
TypeError: React.createRef is not a function. (In 'React.createRef()', 'React.createRef' is undefined)
.
update react to 16.3 React.createRef() this API is added on react 16.3 checkout this https://github.com/facebook/react/pull/12162
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With