Skip to content

Commit 92b045d

Browse files
committed
fix : option updating by props issue
1 parent fbe1500 commit 92b045d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/MultiSelect.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ MultiSelect.defaultProps = {
3838
disableSearch: false
3939
}
4040

41-
function MultiSelect({
41+
export default function MultiSelect({
4242
options: userOptions,
4343
downArrowIcon,
4444
closeIcon,
@@ -82,7 +82,7 @@ function MultiSelect({
8282
const calculatedWidth = `calc(100% - ${clearable && downArrow ? 60 : downArrow || clearable ? 40 : 5
8383
}px)`
8484

85-
const getValueObjFromOptios = (defaultValue, options) => {
85+
const getValueObjFromOptions = (defaultValue, options) => {
8686
if (!defaultValue) return []
8787
let defaultValArr = defaultValue
8888
const extraValues = []
@@ -138,12 +138,12 @@ function MultiSelect({
138138
if (extraValues.length) {
139139
customValuesGroup = createCustomValueAndOption(extraValues)
140140
}
141-
setOptions([...options, ...customValuesGroup])
141+
setOptions([...userOptions, ...customValuesGroup])
142142
return [...searchedOptions, ...extraValues]
143143
}
144144

145145
useEffect(() => {
146-
if (clearAll && value.length > 0) {
146+
if (clearAll && value.length) {
147147
clearValue()
148148
}
149149
}, [clearAll])
@@ -153,9 +153,9 @@ function MultiSelect({
153153
}, [userOptions])
154154

155155
useEffect(() => {
156-
let preDefinedValue = getValueObjFromOptios(defaultValue, options)
156+
let preDefinedValue = getValueObjFromOptions(defaultValue, options)
157157

158-
if (singleSelect && preDefinedValue.length > 0) {
158+
if (singleSelect && preDefinedValue.length) {
159159
preDefinedValue = [preDefinedValue[0]]
160160
}
161161

@@ -535,5 +535,3 @@ function MultiSelect({
535535
</div>
536536
)
537537
}
538-
539-
export default MultiSelect

0 commit comments

Comments
 (0)