what is ref in react js hooks code example
Example 1: use ref in component reactjs
function MyFunctionComponent() { return <input />;
}
class Parent extends React.Component {
constructor(props) {
super(props);
this.textInput = React.createRef(); }
render() {
return (
<MyFunctionComponent ref={this.textInput} /> );
}
}
Example 2: use ref in component reactjs
class CustomTextInput extends React.Component {
}
Example 3: use ref in component reactjs
function CustomTextInput(props) {
return (
<div>
<input ref={props.inputRef} /> </div>
);
}
class Parent extends React.Component {
render() {
return (
<CustomTextInput
inputRef={el => this.inputElement = el} />
);
}
}