fix: duplicated itens inside the UiKit's Select (#5107)

* fix: duplicated itens inside the UiKit's Select

* add useMemo
This commit is contained in:
Reinaldo Neto 2023-06-26 23:24:43 -03:00 committed by GitHub
parent 51cf4e5cd9
commit 8bb5af25ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import { StyleSheet } from 'react-native';
import RNPickerSelect from 'react-native-picker-select';
@ -55,6 +55,14 @@ export const Select = ({ options = [], placeholder, onChange, loading, disabled,
backgroundColor: themes[theme].backgroundColor
};
const placeholderObject = useMemo(
() =>
placeholder && !items.some(item => item.label === textParser([placeholder]))
? { label: textParser([placeholder]), value: null }
: {},
[items.length, placeholder?.text]
);
const Icon = () =>
loading ? (
<ActivityIndicator style={styles.loading} />
@ -66,7 +74,7 @@ export const Select = ({ options = [], placeholder, onChange, loading, disabled,
// @ts-ignore lib types issues. We need to fork it and maintain or find another lib
<RNPickerSelect
items={items}
placeholder={placeholder ? { label: textParser([placeholder]), value: null } : {}}
placeholder={placeholderObject}
useNativeAndroidPickerStyle={false}
value={selected}
disabled={disabled}