Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda