From 479837e5f2abc187511334688c250b3543082282 Mon Sep 17 00:00:00 2001 From: peacechen Date: Mon, 12 Jul 2021 10:18:59 -0500 Subject: [PATCH] Use keyExtractor in onChange() (#140) --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e8224b7..a7ece24 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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);