I am using React and have the following component:
import React from 'react';
function Calculate({ work }) {
var inputValue = 0;
const totalAmountToBePaid = () => {
inputValue++;
console.log("=====> Total Amount To Be Paid", work);
console.log(inputValue);
};
return (
<div>
<header className="App-header">
<input type="number" id="amount" value={inputValue} readOnly></input>
<button onClick={totalAmountToBePaid}>Total Amount To Be Paid</button>
</header>
</div>
)
}
export default Calculate;
When I click the button, I need it to update value of the input by calling the totalAmountToBePaid function.
The above solution just leave the value of the input on its default value of 0.
I am new to React, so please excuse my ignorance. I think I might need to gave a state object.
Thank you