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.
CodePudding user response:
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.