Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
How to update value in a different file React Native

Inside App.js I have an authorized variable. Depending on it's value (true/false) App function returning the exact components.

App.js
....
import React, { useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import MyDrawer from './components/Drawer'
import AuthStack from './components/AuthStack'

export default function App() {
  const [authorized, setAuthorized] = useState(false)

  return authorized ? (
    <NavigationContainer>
      <MyDrawer />
    </NavigationContainer>
  ) : (
    <NavigationContainer>
      <AuthStack />
    </NavigationContainer>
  );
}

Inside the AuthStack I have a OTPScreen component:

OTPScreen.js
....
import React, { useState } from 'react';
import { View, Text, StyleSheet, TextInput, StatusBar, Pressable } from 'react-native';

export default function OTPScreen(props) {
    const [code, setCode] = useState('');
    const confirm = props.route.params.confirm;

    const OTPVerify = async () => {
        try {
            let data = await confirm.confirm(code);
            // Update "authorized" value here
        } catch (error) {
            console.log('Invalid code')
        }
    }

    return (
        <View style={styles.mainContainer}>
            <StatusBar backgroundColor='#9394ee' barStyle='light-content' />
            <View style={styles.mainContent}>
                <View style={styles.codeBar}>
                    <TextInput
                        style={styles.input}
                        placeholder="Enter code"
                        placeholderTextColor='#000000'
                        value={code}
                        onChangeText={setCode}
                    />
                </View>
                <Pressable style={styles.button} onPress={OTPVerify}>
                    <Text style={styles.buttonText}>Sign in</Text>
                </Pressable>
            </View>
        </View>
    )
}

I need to change the authorized value inside the App.js from a OTPScreen.js. How can I do that?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

This might work:

// App.js
const authorize = () => {
   setAuthorized(true);
}

// App.js
<AuthStack onAuthorize={authorize} />

// OTPScreen
<OTPScreen onAuthorize={props.onAuthorize} />

// OTPScreen
const OTPVerify = async () => {
    try {
        let data = await confirm.confirm(code);
        props.onAuthorize();
    } catch (error) {
        console.log('Invalid code')
    }
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!