Skip to content

Commit 127f559

Browse files
authored
inputValue 추가로 인한 사이드 이펙트 수정 (#178)
1 parent 11e2223 commit 127f559

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

react-multi-email/ReactMultiEmail.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
7575
const findEmailAddress = React.useCallback(
7676
async (value: string, isEnter?: boolean) => {
7777
const validEmails: string[] = [];
78-
let inputValue = '';
78+
let _inputValue = '';
7979
const re = new RegExp(delimiter, 'g');
8080
const isEmail = validateEmail || isEmailFn;
8181

@@ -110,13 +110,13 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
110110
addEmails('' + email);
111111
} else {
112112
if (arr.length === 1) {
113-
inputValue = '' + arr.shift();
113+
_inputValue = '' + arr.shift();
114114
} else {
115115
arr.shift();
116116
}
117117
}
118118
} else {
119-
inputValue = '' + arr.shift();
119+
_inputValue = '' + arr.shift();
120120
}
121121
}
122122
} else {
@@ -127,7 +127,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
127127
setSpinning(false);
128128
} else {
129129
if (arr.length === 1) {
130-
inputValue = '' + arr.shift();
130+
_inputValue = '' + arr.shift();
131131
} else {
132132
arr.shift();
133133
}
@@ -152,36 +152,36 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
152152
const email = stripDisplayName ? value.split('<')[1].split('>')[0] : value;
153153
addEmails(email);
154154
} else {
155-
inputValue = value;
155+
_inputValue = value;
156156
}
157157
} else {
158-
inputValue = value;
158+
_inputValue = value;
159159
}
160160
} else {
161161
// handle promise
162162
setSpinning(true);
163163
if ((await validateEmail?.(value)) === true) {
164164
addEmails(value);
165165
} else {
166-
inputValue = value;
166+
_inputValue = value;
167167
}
168168
setSpinning(false);
169169
}
170170
} else {
171-
inputValue = value;
171+
_inputValue = value;
172172
}
173173
}
174174
}
175175

176176
setEmails([...emails, ...validEmails]);
177-
setInpValue(inputValue);
177+
setInpValue(_inputValue);
178178

179179
if (validEmails.length) {
180180
onChange?.([...emails, ...validEmails]);
181181
}
182182

183-
if (inputValue !== inputValue) {
184-
onChangeInput?.(inputValue);
183+
if (inputValue !== _inputValue) {
184+
onChangeInput?.(_inputValue);
185185
}
186186
},
187187
[
@@ -190,6 +190,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
190190
delimiter,
191191
emails,
192192
enable,
193+
inputValue,
193194
onChange,
194195
onChangeInput,
195196
onDisabled,
@@ -201,9 +202,8 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
201202
const onChangeInputValue = React.useCallback(
202203
async (value: string) => {
203204
await findEmailAddress(value);
204-
onChangeInput?.(value);
205205
},
206-
[findEmailAddress, onChangeInput],
206+
[findEmailAddress],
207207
);
208208

209209
const removeEmail = React.useCallback(

0 commit comments

Comments
 (0)