Skip to content

Instantly share code, notes, and snippets.

@rzymek
Created February 4, 2021 19:20
Show Gist options
  • Save rzymek/6bff654a58d9fa04ceed223c7cd7f72a to your computer and use it in GitHub Desktop.
Save rzymek/6bff654a58d9fa04ceed223c7cd7f72a to your computer and use it in GitHub Desktop.
function Calculator() {
const [input, setInput] = useState('');
const [result, setResult] = useState<number>()
return <div>
<input data-testid='expression' onChange={e => setInput(e.target.value)}/>
<button data-testid='calculate' onClick={() => setResult(eval(input))}/>
<div data-testid='result'>{result}</div>
</div>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment