Skip to content

Conversation

apolloid
Copy link

@apolloid apolloid commented Sep 19, 2023

…that of default option

Hi KoalaBear,
Great Jobs for the first draft in this functionality which I need but upon trying to implement your code, I found that there are some issues where the owner might reject it, mainly:

  1. The defaultOption implemented by original owner is in the form of {key:any, value:any}, however, the current implementation for for defaultOptions is in the form of ['valueA', 'valueB'].
  2. It does not work with the save functionality. It will setselected to value instead of key even if I have set it to save='key'.

For above issues, I had corrected them and updated an example in README:
import { MultipleSelectList } from 'react-native-dropdown-select-list'

const App = () => {

  const [selected, setSelected] = React.useState([]);
  
  const data = [
    {key:'1',value:'Jammu & Kashmir'},
    {key:'2',value:'Gujrat'},
    {key:'3',value:'Maharashtra'},
    {key:'4',value:'Goa'},
  ]

  return(
    <MultipleSelectList 
      onSelect={() => alert(selected)}
      setSelected={(val) => setSelected(val)} 
      data={data} 
      save="key"
      defaultOptions={[ {key:'1', value:'Jammu & Kashmir' }, {key:'4', value:'Goa' }]}   //default selected options
    />
  )

};

@apolloid
Copy link
Author

while using the package, found one more issue,
initialize defaultOptions=[]
as without this those people who never declare props defaultOptions will have error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant