Skip to content

Commit

Permalink
Added Error Boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
avinashsivaraman committed Jun 20, 2019
1 parent 525e764 commit 96ff857
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/ButtonPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class ButtonPanel extends React.Component {
}

componentWillUnmount(){
document.removeEventListener('keydown')
document.removeEventListener('keydown', this.mapKeyToButton)
}
render() {
return (
Expand Down
15 changes: 11 additions & 4 deletions src/lib/Calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ export default class Calculator extends React.Component {
replacement.forEach((item) => {
cur = pastedData.replace(item.dist, item.reg);
});
this.setState({
cur: evaluate(cur).toString(),
last: cur
})
try {
this.setStateAndNotify({
cur: evaluate(cur).toString(),
last: cur
})
} catch (e) {
this.setStateAndNotify({
cur,
last: 'Not a valid expression'
})
}
}
}

Expand Down

0 comments on commit 96ff857

Please sign in to comment.