lawnstarter / react-native-picker-select

🔽 A Picker component for React Native which emulates the native <select> interfaces for iOS and Android
https://npmjs.com/package/react-native-picker-select
MIT License
1.74k stars 499 forks source link

TypeError: Cannot read property 'label' of undefined #417

Closed zaabdn closed 3 years ago

zaabdn commented 3 years ago

I want to make two picker selects, like that

this is a generate my data

const generateSubject = () => {
    const theSubject = dataSubjects?.subjectsConnection?.data?.map((item) => {
      return (
        item && {
          key: item.id,
          value: item.id,
          label: item.name,
        }
      )
    })
    return theSubject
  }

  const generateBasicCompetence = () => {
    const theBasicCompetence = dataBasicCompetences?.basicCompetencesConnection?.data?.map(
      (item) => {
        return (
          item && {
            key: item.id,
            value: item.id,
            label: item.code,
          }
        )
      },
    )
    return theBasicCompetence
  }

this is my rnpickerselect, but I have error like this TypeError: Cannot read property 'label' of undefined

                      <RNPickerSelect
                            key={index}
                            placeholder={{
                              label: translations["choose.subject"],
                              color: theme.colors.placeholder,
                            }}
                            onValueChange={(value) => {
                              setSubjectAssignment((prev) => {
                                prev[index].subjectId = value
                                return [...prev]
                              })
                            }}
                            items={generateSubject()}
                            style={{
                              inputAndroid: {
                                color: theme.colors.text,
                              },
                            }}
                          />
                         <RNPickerSelect
                            key={index + 1}
                            placeholder={{
                              label: translations["select.basic.competences"],
                              color: theme.colors.placeholder,
                            }}
                            onValueChange={(value) => {
                              setSubjectAssignment((prev) => {
                                prev[index].basicCompetenceId = value
                                return [...prev]
                              })
                            }}
                            items={generateBasicCompetence()}
                            style={{
                              inputAndroid: {
                                color: theme.colors.text,
                              },
                            }}
                          />

can anyone help me?

lfkwtz commented 3 years ago

@zaabdn this issue was automatically closed because it did not follow one of the available issue templates. See here for available options.

zaabdn commented 3 years ago

@lfkwtz what do you mean not following one of the available issue templates?