Skip to content

Commit

Permalink
move reg exp to state variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kimprice committed Sep 10, 2024
1 parent 368cca1 commit 1d5c81f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions react-common/components/controls/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const Input = (props: InputProps) => {

const [value, setValue] = React.useState(initialValue || "");
const [expanded, setExpanded] = React.useState(false);
const [pattern, setPattern] = React.useState(filter ? new RegExp(filter) : undefined);

let container: HTMLDivElement;

Expand All @@ -86,9 +87,8 @@ export const Input = (props: InputProps) => {

const changeHandler = (e: React.ChangeEvent<any>) => {
let newValue = (e.target as any).value;
if (newValue && filter) {
const pat = new RegExp(filter);
newValue = newValue.match(pat)?.join("") || "";
if (newValue && pattern) {
newValue = newValue.match(pattern)?.join("") || "";
}
if (!readOnly && (value !== newValue)) {
setValue(newValue);
Expand Down

0 comments on commit 1d5c81f

Please sign in to comment.