Skip to content

Commit

Permalink
shouldnot always call setState on handleKeyUp func (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin-front authored and paranoidjk committed Aug 3, 2017
1 parent bd676fd commit 8a057c3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,22 @@ export default class Pagination extends React.Component {

handleKeyUp = (e) => {
const inputValue = e.target.value;
const currentInputValue = this.state.currentInputValue;
let value;

if (inputValue === '') {
value = inputValue;
} else if (isNaN(Number(inputValue))) {
value = this.state.currentInputValue;
value = currentInputValue;
} else {
value = Number(inputValue);
}

this.setState({
currentInputValue: value,
});
if (value !== currentInputValue) {
this.setState({
currentInputValue: value,
});
}

if (e.keyCode === KEYCODE.ENTER) {
this.handleChange(value);
Expand Down

0 comments on commit 8a057c3

Please sign in to comment.