Goal:
Get value from the textbox when you click on the button
Problem:
The value don't display in the console.
"Uncaught Error: Function components cannot have string refs. We recommend using useRef() instead"
How do you apply useRef() in this context?
Stackblitz
https://stackblitz.com/edit/react-ts-mcn4jd?file=index.tsx
Info:
*Newbie in react TS
Thank you!
import React from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
function test() {
// Get the value and display it at consol
//var name = refs.mytext.value;
var element = document.getElementById("ddddd");
console.log(element);
}
return (
<div className="App">
<input type="text" id="ddddd" ref="mytext" />
<button onClick={() => test()}>Add</button>
</div>
);
}
export default App;