EDIT: Now you can with React Hooks. See the answer of Ante Gulin.
You cannot access React-like methods (e.g. componentDidMount , componentWillReceiveProps , etc.) for stateless components, including refs . Check out this discussion on GH for a complete convo.
The idea of statelessness is that no instance (state) is created for it. Thus, you cannot attach ref , since there is no state to which it can be bound.
It is best to pass a callback when the component changes, and then assign this text to the parent state.
Or you can discard the stateless component altogether and use the regular class component.
From the documents ...
You cannot use the ref attribute on functional components because they have no instances. However, you can use the ref attribute inside the render function of the functional component.
function CustomTextInput(props) { // textInput must be declared here so the ref callback can refer to it let textInput = null; function handleClick() { textInput.focus(); } return ( <div> <input type="text" ref={(input) => { textInput = input; }} /> <input type="button" value="Focus the text input" onClick={handleClick} /> </div> ); }
source share