react get input value on button click functional component 1

react get input value on button click functional component

const input = props => {

let textInput = React.createRef();

function handleClick() {
  console.log(textInput.current.value);
}

return (
    
) }

Here is what the above code is Doing:
1. We create a ref called textInput.
2. We pass the ref to the input element.
3. We use the ref in the handleClick function to get the value of the input element.

Similar Posts