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 :: why can i put comments in some json files 
Javascript :: set selected value of dropdown using formcontrol in angular 
Javascript :: get react form input data, How get form input data in react 
Javascript :: javascript string proper case 
Javascript :: react sign in with linkedin 
Javascript :: Could not resolve project :react-native-iap mergedebugassets 
Javascript :: parseint js 
Javascript :: javascript array column 
Javascript :: js dom siblings 
Javascript :: moment not translating 
Javascript :: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String 
Javascript :: react native shadow android 
Javascript :: javascript get magnitude of number 
Javascript :: get static props 
Javascript :: for in range javascript 
Javascript :: How to create a GUID / UUID 
Javascript :: jspdf 
Javascript :: Prevent default event behavior 
Javascript :: scrollintoview javascript 
Javascript :: JavaScript try...catch in setTimeout 
Javascript :: currentTime(); javascript 
Javascript :: jsjs trigger window error 
Javascript :: how to add options to select in jquery array 
Javascript :: Vue JS Production mode refresh causing 404 error 
Javascript :: post to /wp-json/wp/v2/media 
Javascript :: babel debugging 
Javascript :: nextjs framer motion 
Javascript :: delete an element to an array 
Javascript :: array of array key value javascript 
Javascript :: convert html to pdf using javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =