Skip to content

Commit

Permalink
Use keyExtractor in onChange() (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
peacechen committed Jul 12, 2021
1 parent 97913c5 commit 479837e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const defaultProps = {
onChange: () => {},
onModalOpen: () => {},
onModalClose: () => {},
keyExtractor: (item) => item.key,
labelExtractor: (item) => item.label,
componentExtractor: (item) => item.component,
keyExtractor: (item) => item && item.key,
labelExtractor: (item) => item && item.label,
componentExtractor: (item) => item && item.component,
listType: 'SCROLLVIEW',
visible: false,
closeOnChange: true,
Expand Down Expand Up @@ -175,7 +175,8 @@ export default class ModalSelector extends React.Component {
}

onChange = (item) => {
if (!item || item.key == null) { // == coercion
const key = this.props.keyExtractor(item);
if (!item || key == null) { // == coercion
return;
}
this.props.onChange(item);
Expand Down

0 comments on commit 479837e

Please sign in to comment.