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

314
Visualizações
Passing a list of values between pages in react native

I am new to React/React-native. I am trying to add a key-value pair in the JSON body which is the output of screen 1 having the following components:

  1. A textbox which is to input a name
  2. A textbox which is to input an email
  3. A button, Types that navigates to Screen 2

The components on screen 2 are:

  1. Two single-option dropdown lists with labels type 1 and type 2 that have three options each- "a", "b", "c".
  2. A SAVE button to save the options chosen.

Initially, the JSON data produced from screen 1 WITHOUT the functionality of the Types button was:

body: JSON.stringify({
name: Name,
email: Email})

but now I want the output from screen 1 to be:

body: JSON.stringify({
name: Name,
email: Email,
types:[type1:"a", type2:"b"]
})

where type1 and type2 are the labels of the two dropdown lists and the options selected are "a" and "c" respectively after pressing a SAVE button on screen 2 and then navigating to screen 1. I have used the following useState methods for name and email for screen1:

const [Name, setName] = useState("")
const [Email, setEmail] = useState("")

and after making Types as a functional button on screen 1:

const [Name, setName] = useState("")
const [Email, setEmail] = useState("")
const [Types, setTypes] = useState([])

The below code is to update the name and the email with a Types button on screen 1:

<TextInput
label='Name'
value={Name}
onChangeText={text => setName(text)}
/>

<TextInput
label='Email'
value={Email}
onChangeText={text => setEmail(text)}
/>

<Button onPress={() => navigation.navigate("screen_2")>
Types
</Button>

What should be my onPress function in the button, Types(Screen 1) and button, Save(Screen 2) and how do I update the JSON body after saving my options on screen 2?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you're using something like React Router, you should check how to pass state with it. If not you might want to create a Redux store to save state relevant to the whole application

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