简体   繁体   中英

react-native-dropdown-picker default value

does anyone have an example of a default value used in the library react-native-dropdown-picker used hooks e function, or another libre that makes this msm function simpler.

export default function OrphanageData() {

const [date, setDate] = useState(new Date())
const [value, setValue] = useState();
const [items, setItems] = useState([{}]);
let controller;

return (

<>
     <StatusBar backgroundColor="#15c3d6"/>

    <ScrollView style={styles.container} contentContainerStyle={{ padding: 24 }}>
    
        <Text style={styles.title}>Compras</Text>
        

        <Text style={styles.label}> ID - Brinco</Text>
        <TextInput
            style={styles.input}
        />

    <DropDownPicker
        items={items}
        controller={instance => controller = instance}
        onChangeList={(items, callback) => {
            new Promise((resolve, reject) => resolve(setItems(items)))
                .then(() => callback())
                .catch(() => {});
        }}
    
        defaultValue={value}
        onChangeItem={item => setValue(item.value)}
    />    

      

        <RectButton style={styles.nextButton} onPress={() => {}}>
            <Text style={styles.nextButtonText}>Cadastrar</Text>
        </RectButton>
    </ScrollView>
</>

) }

This might help (Using Hooks)

export default function OrphanageData() {

  const [value, setValue] = useState('usa');
  const [items, setItems] = useState([
         {label: 'USA', value: 'usa'},
         {label: 'UK', value: 'uk'},
         {label: 'France', value: 'france'},
    ]);

  return(
    <DropDownPicker
          items={items}
          defaultValue={value}
          onChangeItem={item => setValue(item.value)}
          .....
    />
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM