Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get react form input using ref react 18

Watch this example video 
https://www.youtube.com/watch?v=LDS1ll93P-s&t=843s

in summary import useRef from react

inside the component 
use the useRef to create an inputRef 
import {useRef} from "react";
const FormInputComponent = () => {
  
const inputRef = useRef();


const handleSubmit = e => {
	// get the ref value
  const inputValue = inputRef.current.value;
  // clear the input
  inputRef.current.value = "";
  // do stuff with the input data
}
return(
<> 
  //in the form 
	<form onSubmit={handleSubmit}>
		<input type="text" ref={inputRef} />
	</form>
</>
); 
}
 
PREVIOUS NEXT
Tagged: #react #form #input #ref #react
ADD COMMENT
Topic
Name
8+9 =