I'm building a React calculator that allows the user to type input into the form and it performs the operation, this is what I have so far in my App.js folder
function App() {
const [output ,setOutput]=useState(0);
const [text, setText]=useState('');
function Clear(){
setOutput(0)
}
function Subtraction() {
setOutput(Number(output)-Number(text));
}
function Addition() {
setOutput(Number(output)+Number(text));
}
function valueOnChange(e){
setText(event.target.value);
}
return (
<main>
<h2>Calculator for Add & Subtract</h2>
<input type="Number" placeholder="Enter the number for add and subtract" onChange={valueOnChange} value={text}/>
<button onClick={Addition} >Add</button>
<button onClick={Clear} >Clear</button>
<button onClick={Subtraction}>Subtract</button>
<div>
<span>Result</span>
<div id="Result">{output}</div>
</div>
</main>
);
}
export default App;
On this line:
`"function valueOnChange(e){
setText(event.target.value);" `
is where I'm getting the error. Can anyone help me out? Not sure how to fix it.