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

260
Views
React Native: Conditionally include tab in tab navigator based on input prop

In my React Native app I have a component, and a tab navigator within that component, like this:

class Screen extends Component {
    render() {
        return(
            <View>
                <TabNav/>
            </View>
        )
    }
}


export const TabNav = createAppContainer(createBottomTabNavigator(
    {
        A: {
            screen: A,
        },
        B: {
            screen: B
        },
        C: {
            screen: C
        }             
    }
));

I want to include C conditionally, based on a prop passed from Screen. So I tried this:

class Screen extends Component {
    render() {
        return(
            <View>
                <TabNav
                    flag={true}
                />
            </View>
        )
    }
}


export const TabNav = createAppContainer(createBottomTabNavigator(
    {
        A: {
            screen: A,
        },
        B: {
            screen: B
        },
        ...(this.props.flag ? {C: {
            screen: C,
        }} : {}),                 
    }
));

but it throws the error Cannot read property 'props' of undefined. How can I change this so that I can pass props from Screen to TabNav?

I'm using

"react-navigation": "^4.0.10",
"react-navigation-tabs": "^2.7.0",
about 4 years ago · Juan Pablo Isaza
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!