Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
How to store multiple values separately from the native base picker

enter image description here

I have product attributes like the image above for which I'm mapping the otherDetails array to get the keys i.e. size, color and its variations like small, large etc. To get the variations I'm mapping productValue array. Then I'm showing it in the picker like this

             {product.otherDetails.map((item) => (
                <View style={styles.mainText}>
                  <Text
                    style={{
                      fontSize: RFPercentage(1.6),
                      marginLeft: width / 3,
                      textTransform: "uppercase",
                    }}
                  >
                    {item.productKey}
                  </Text>
                  <View style={{ width: width / 3.2 }}>
                    <Picker
                      note
                      mode="dropdown"
                      selectedValue={attributes}
                      onValueChange={onChangeAttributes.bind(this)}
                    >
                      <Picker.Item label="Select" value="select" />
                      {item.productValue?.map((product) => (
                        <Picker.Item
                          label={product.attributeName}
                          value={product.attributeName.toLowerCase()}
                        />
                      ))}
                     </Picker>

Its rendering fine on the UI but now I want to store the user choice w.r.t the keys. For instance we have two productKeys i.e. size and color, if the user chooses small from the size key and red from the color key. How can I store them separately in a state? and also be able to update the choices w.r.t the keys.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can maintain a state of selected attributes, for instance:

this.state = {
    ...
    ...
    selectedAttributes: []
}

Then when rendering the picker, the onValueChange would be:

<Picker
    onValueChange={(newValue) => {
        let selectedAttributes = {...this.state.selectedAttributes}
        selectedAttributes[item.productKey] = newValue;
        this.setState({selectedAttributes})
    })>
    ...
</Picker>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda