Я использую самоцвет для реактивных рельсов в моем проекте ruby on rails. Я пытаюсь добавить ссылку на мой элемент DOM. Это мой компонент:
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>
);
}
};
Когда я пытаюсь загрузить страницу в браузере, в консоли появляется следующее сообщение:
TypeError: React.createRef is not a function. (In 'React.createRef()', 'React.createRef' is undefined)
.