Skip to content

Commit 63bba0c

Browse files
author
Ivan Uzun
committed
fix array comparison
1 parent 6224300 commit 63bba0c

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sm-select",
3-
"version": "0.4.6",
3+
"version": "0.4.7",
44
"description": "React Multi/Single Select Component",
55
"main": "./dist/index.js",
66
"module": "./es/index.js",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import T from 'prop-types';
33

4-
import {areValuesEqual, omitDirtyValues} from './utils';
4+
import {areArraysEqual, omitDirtyValues} from './utils';
55
import {DropDown} from './DropDown';
66
import {DefValue} from './default/DefValue';
77
import {DefTag} from './default/DefTag';
@@ -77,7 +77,7 @@ export class MultiSelect extends React.Component {
7777
const {props: {value, options}, is} = this;
7878
const clearCurrValue = omitDirtyValues(options, value, is('single'));
7979
const clearPrevValue = omitDirtyValues(options, prev.value, is('single'));
80-
if (!areValuesEqual(clearCurrValue, clearPrevValue)) this.setState({value})
80+
if (!areArraysEqual(clearCurrValue, clearPrevValue)) this.setState({value})
8181
}
8282

8383
onTagRemove = (index, event) => {

src/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const defaultFilterOptions = (options, filter) =>
1313
option.label.toLowerCase().includes(filter.toLowerCase())
1414
);
1515

16-
export const areValuesEqual = (first, second) => {
17-
if (!Array.isArray(first)) return first === second;
18-
return !first.reduce((A, item, idx) => item !== second[idx] ? [...A, item] : A,[]).length
16+
export const areArraysEqual = (first, second) => {
17+
if (first.length !== second.length) return false;
18+
return !first.reduce((A, item, idx) => item !== second[idx] ? [...A, item] : A, []).length
1919
};
2020

2121
export const omitDirtyValues = (origin, part, single) => {

0 commit comments

Comments
 (0)