question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError when providing default value in DropDownPicker

See original GitHub issue

I am creating a dropdown picker with remote search enabled. And for the default value I am using value from the redux state. But upon app refresh, I am getting the following error,

TypeError: _value.includes is not a function. (In '_value.includes(item[_schema.value])', '_value.includes' is undefined)

Current Usage:

<DropDownPicker
    addCustomItem={true}
    disableLocalSearch={true}
    items={currentMeta.meta}
    open={pickerState && pickerState[metaKey]}
    onChangeSearchText={
      (searchKey) => handleRemoteDropDownSearch(
        searchKey, currentMeta
      )
    }
    onOpen={() => handleDropDownOpen(metaKey)}
    onClose={() => handleDropDownClose()}
    placeholder={currentMeta.placeholder}
    {...getDropDownStyles(currentMeta.meta.length)}
    searchable={true}
    searchPlaceholder={'Start typing...'}
    setValue={
      (newValue) => handleDropDownChange(
        currentMeta.stateKey, newValue()
      )
    }
    value={userData[currentMeta.stateKey]}
    zIndex={2000}
    {...dropDownSearchStyles}
/>

userData has key-values as per the key from currentMeta.stateKey E.g. If currentMeta.stateKey is university then userData[currentMeta.stateKey] return My University (string)

It would be great if someone can help on this

@hossein-zare

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hossein-zarecommented, May 6, 2021

The callback was returning undefined because you’d not passed the current value. in the renderListItem method undefined.includes was complaining.

0reactions
orhangazicommented, Apr 16, 2022

Hello,

Share code of the handleDropDownChange function. The newValue() needs the current value in the setValue property.

setValue={(newValue) => handleDropDownChange(
  currentMeta.stateKey, newValue()
)}

If userData[currentMeta.stateKey] is your state variable:

newValue(userData[currentMeta.stateKey])

Thank you so much. I am using redux and I was looking for this answer everywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-dropdown-picker default value - Stack Overflow
Your question is not clear, you can use the value field the array to match with the default value, can you explain your...
Read more >
Unable to select multiple values · Issue #389 - GitHub
When I select one option they throw me this error: TypeError: ... defaultValue[0]') in react-native-dropdown-picker in version ^3.8.3 please ...
Read more >
Usage | React Native Dropdown Picker - GitHub Pages
This only works with multiple item pickers. Type, Default. number, null. max ​. Specifies the maximum number of items.
Read more >
[Solved]-default value comes first useState-React Native
const [countryCode, setCountryCode] = useState< PhoneInputProps['defaultCode'] | string | null >(); useEffect(() => { (async () => { const { status } ...
Read more >
react-native-picker-select | Yarn - Package Manager
For iOS, by default we are wrapping an unstyled TextInput component. You can then pass down styles to customize it to your needs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found