Listing 9-1: Creating a Ref in a Class Component
import React,{Component} from 'react';
class TextReader extends Component {
constructor(props) {
super(props);
this.textView = React.createRef();
}
render() {
return (
<textarea ref={this.textView} value={this.props.bookText} />
);
}
}
export default TextReader;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.