Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ref in functional components

function CustomTextInput(props) {
  // textInput must be declared here so the ref can refer to it  const textInput = useRef(null);  
  function handleClick() {
    textInput.current.focus();  }

  return (
    <div>
      <input
        type="text"
        ref={textInput} />      <input
        type="button"
        value="Focus the text input"
        onClick={handleClick}
      />
    </div>
  );
}
Comment

ref in functional components

function MyFunctionComponent() {  return <input />;
}

class Parent extends React.Component {
  constructor(props) {
    super(props);
    this.textInput = React.createRef();  }
  render() {
    // This will *not* work!
    return (
      <MyFunctionComponent ref={this.textInput} />    );
  }
}
Comment

PREVIOUS NEXT
Code Example
::  
Javascript ::  
::  
::  
Javascript ::  
Javascript ::  
Javascript ::  
::  
::  
:: fontawesome icon size 1.5 angular 
:: how to export module in node js 
::  
::  
::  
::  
Javascript ::  
::  
::  
::  
:: resize image in node.js 
Javascript ::  
::  
Javascript ::  
::  
Javascript :: npm install could not resolve peerDependencies 
:: vuejs set default value for prop 
::  
:: urlsearchparams to object 
:: render first index active tabs in reactjs 
Javascript ::  
ADD CONTENT
Topic
Content
Source link
Name
1+1 =