I'm following the React Tutorial and got stuck on how to use React.findDOMNode
.
Here is my code:
export class CommentForm extends React.Component<{}, {}> {
handleSubmit(e: React.FormEvent) {
e.preventDefault();
console.log(React.findDOMNode(this.refs['author']));
}
render() {
return <form className="commentForm" onSubmit={ e => this.handleSubmit(e) }>
<input type="text" placeholder="Your name" ref="author" />
<input type="text" placeholder="Say something..." ref="text" />
<input type="submit" value="Post" />
</form>;
}
}
Calling console.log(React.findDOMNode(this.refs['author']));
gives me back <input type="text" data-reactid=".0.2.0" placeholder="Your name">
in the console.
However, I cannot figure out how to retrieve the value of the input element (what I typed in the input box).
So far I've tried the following along with a few others:
React.findDOMNode(this.refs['author']).value; // "value" does not exist on type "Element"
React.findDOMNode(this.refs['author']).getAttribute('value'); // null
React.findDOMNode(this.refs['author']).textContent; // null
In intellisense I can see the following, but I still cannot figure out what to call here.
I'm using the type definitions from DefinitedlyTyped. Also, I'm new to front-end development, so maybe my approach is wrong.