Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inputValue 추가로 인한 사이드 이펙트 수정 #178

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions react-multi-email/ReactMultiEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
const findEmailAddress = React.useCallback(
async (value: string, isEnter?: boolean) => {
const validEmails: string[] = [];
let inputValue = '';
let _inputValue = '';
const re = new RegExp(delimiter, 'g');
const isEmail = validateEmail || isEmailFn;

Expand Down Expand Up @@ -110,13 +110,13 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
addEmails('' + email);
} else {
if (arr.length === 1) {
inputValue = '' + arr.shift();
_inputValue = '' + arr.shift();
} else {
arr.shift();
}
}
} else {
inputValue = '' + arr.shift();
_inputValue = '' + arr.shift();
}
}
} else {
Expand All @@ -127,7 +127,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
setSpinning(false);
} else {
if (arr.length === 1) {
inputValue = '' + arr.shift();
_inputValue = '' + arr.shift();
} else {
arr.shift();
}
Expand All @@ -152,36 +152,36 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
const email = stripDisplayName ? value.split('<')[1].split('>')[0] : value;
addEmails(email);
} else {
inputValue = value;
_inputValue = value;
}
} else {
inputValue = value;
_inputValue = value;
}
} else {
// handle promise
setSpinning(true);
if ((await validateEmail?.(value)) === true) {
addEmails(value);
} else {
inputValue = value;
_inputValue = value;
}
setSpinning(false);
}
} else {
inputValue = value;
_inputValue = value;
}
}
}

setEmails([...emails, ...validEmails]);
setInpValue(inputValue);
setInpValue(_inputValue);

if (validEmails.length) {
onChange?.([...emails, ...validEmails]);
}

if (inputValue !== inputValue) {
onChangeInput?.(inputValue);
if (inputValue !== _inputValue) {
onChangeInput?.(_inputValue);
}
},
[
Expand All @@ -190,6 +190,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
delimiter,
emails,
enable,
inputValue,
onChange,
onChangeInput,
onDisabled,
Expand All @@ -201,9 +202,8 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
const onChangeInputValue = React.useCallback(
async (value: string) => {
await findEmailAddress(value);
onChangeInput?.(value);
},
[findEmailAddress, onChangeInput],
[findEmailAddress],
);

const removeEmail = React.useCallback(
Expand Down
Loading