React stateless component this.refs..value?

后端 未结 7 1630
故里飘歌
故里飘歌 2020-12-03 01:09

I don\'t know if I\'m doing this correctly... If I want to get value from an input I use this.refs.whatever.value.trim() but if that input is a stateless function component

相关标签:
7条回答
  • 2020-12-03 01:38
    import React, { useEffect, useRef } from 'react';
    
    function TextFocusTest () {
      const textRef = useRef(null);
    
      useEffect(() => {
         textRef.current.focus();
      });
    
      return(
        <input ref{textRef} type="text">
      );
    
    } 
    
    export default TextFocusTest;
    
    0 讨论(0)
提交回复
热议问题