Skip to content

Commit

Permalink
fix: add useCallback to TextInput onChange handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaaban0 committed Nov 20, 2020
1 parent de27965 commit 783e2c0
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ export const TextInput = (props: TextInputProps) => {
}
};

const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
e.persist();
if (disabled || isReadOnly) return;
const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
e.persist();
if (disabled || isReadOnly) return;

if (onChange) {
onChange(e);
}
setValueState(e.currentTarget.value);
};
if (onChange) {
onChange(e);
}
setValueState(e.currentTarget.value);
},
[onChange, disabled, isReadOnly],
);

const handleKeyDown = useCallback(
(e: KeyboardEvent<HTMLInputElement>) => {
Expand Down

0 comments on commit 783e2c0

Please sign in to comment.