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

423
Visualizações
React Native: pass variable to another page

I have implemented a way that when I click on a button I pass a variable (an object that I build when the button is clicked) to another page.

Now my problem is in the page that receives this variable, because when I pass this value, I use it to set other const variable and if I'll click another time in the button the variables remains setted as before.

So I have an index.js page that contains the botton

const index = ({}) => {
return (
// others //
 <Permission /> 
)
}

In the Permission.js

const Permission = () => {

 const request = () => {
   let requestVariable 
   // all the logic to populate the requestVariable
   if(//.....){
     requestVariable = {
            id: idRequest,
            requestType: 'permission',
            startDate: myDateVariable
            // ....
   }
   Actions['allPermissions']{(requestVariable : requestVariable  )}
 }

 return (
       <MyButton  type="primary" onPress={() => request()} />
 )
}

So I have my AllPermissions.js

const AllPermission = ({requestVariable}){ const[componentSel, setComponentSel] = useState(0)

return( {componentSel === 0 && <NewPermission requestVariable = {requestVariable } />} ) }

Now in NewPermission I have the problems I talked about

const NewPermission = ({requestVariable }){
    const [type, setType] = useState(requestVariable  ? requestVariable.requestType : 'permission'
    const [startDate, setStartDate] = useState(requestVariable ? requestVariable.startDate : new Date())
//....
}

Now as I said the problem is in new request, because I can access in this page clicking in the button or from a tab. If I click on the button first time, all is setted correctly but If I go to the index.js page and click another time, (so the values that I insert in the object are different) are not showed. How can I do to populate the values in my NewPermission page?

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

0

Try this way

const NewPermission = ({requestVariable }){
    const [type, setType] = useState(requestVariable  ? requestVariable.requestType : 'permission'
    const [startDate, setStartDate] = useState(requestVariable ? requestVariable.startDate : new Date())

 useEffect(() => {
    setType( requestVariable ? requestVariable.requestType : 'permission' );
  }, [requestVariable]);
}
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