2

I just started working with React Native only recently and there was a task I couldn't accomplish. I want to make a screen with a yes/no question. Depending on which one the user chooses, I'll either render a component that I have ready, or just close the screen. Thank you in advance!

2 Answers 2

6

You can also use conditions in the jsx code like

render(){
    return myCondition ? <MyFirstComponent/> : <MySecondComponent/>
}

or even if their is some nesting you can write

    <View>
       {...childrens}
       { myCondition ? <MyFirstComponent/> : <MySecondComponent/>}
    </View>

or even if only some view

        <View>
           {...childrens}
           { myCondition && <View> </View>}
        </View>
Sign up to request clarification or add additional context in comments.

Comments

0

To do conditional rendering in React Native, you can use if statements:

render(){
    if(myCondition){
        return(<MyFirstComponent/>);
    }
    else{
        return(<MySecondComponent/>);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.