'Store a TextField value inside a variable in MaterialUI/React
I have a TextField and would like to take the input and store it in a variable.
<TextField
id="output_elevator-amount"
label="Elevator amount"
color="primary"
// variant="outlined"
type="number"
InputLabelProps={{
shrink: true
}}
InputProps={{
readOnly: true
}}
onChange={(event) => {
setAmount(parseInt(event.target.value));
}}
/>
When I was working with javascript and html I did something like this but now with typescript/MUI/React I'm not sure what to do.
let elevatorAmt = (document.getElementById('output_elevator-amount') as HTMLInputElement);
any help is greatly appreciated.
Solution 1:[1]
If you want to store "somewhere" the variable inputed via onChange, you are already doing by setting setAmount.
I am assuming you are using this [amount, setAmount] = useState(''). Try console logging amount and use it where you need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Magofoco |
