import React, { useState, useEffect } from 'react'; function Calculator() { const [num1, setNum1] = useState(0); const [num2, setNum2] = useState(0); const [result, setResult] = useState(0); useEffect(() => { if (result !== 0) { alert(`The result is ${result}`); } }, [result]); const handleAddition = () => { setResult(num1 + num2); }; const handleSubtraction = () => { setResult(num1 - num2); }; return (
setNum1(+e.target.value)} /> setNum2(+e.target.value)} />

Result: {result}

); } export default Calculator;