Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React, {useState, useEffect} from 'react';
import '../Css/Calculator.css'
const Calculator = () => {
let [result, setResultState] = useState(0)
let [inputDisplay, setInputDisplayState] = useState(0)
let buttonHandler = (num) =>{
if (inputDisplay === 0){
setInputDisplayState(
inputDisplay = String(num)
)
}
else {
setInputDisplayState(
inputDisplay += String(num)
)
}
}
let evaluateResult = ()=>{
}
return (
<div>
<div className='header'>
<h2>{result}</h2>
<h1>{inputDisplay}</h1>
</div>
<div>
<button onClick={()=>buttonHandler('1')}>1</button>
<button onClick={() => buttonHandler('2')}>2</button>
<button onClick={() => buttonHandler('3')}>3</button>
<button onClick={() => buttonHandler('+')}>+</button>
<button onClick={evaluateResult}>=</button>
</div>
</div>
)
};
export default Calculator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.