React Navigation Authentation Flow












0















I configured my Navigators as follows:



App.js



const AppStack = createStackNavigator ({Home: HomeScreen});
const AuthStack = createStackNavigator({ Login: Login},{ headerMode: 'none' });

export default createSwitchNavigator(
{
App: AppStack,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}
);


The Login can be three different component: Username/Password, Pincode, Fingerprint. In the Login component i use conditional rendering for show te right screen:



Login.js



if(){
return(<Fingerprint navigation={this.props.navigation}}/>)
} else if (){
return(<Password navigation={this.props.navigation}/>)
} else if (){
return(<Pincode navigation={this.props.navigation}}/>)
}


When i want to switch between this components i used setState() so the Login.js can re-render and show the right screen based on the if-else if statement in the code section above.



Now i my question, is this the right implementation with performance in mind? For example when I wanna show Pincode instead of Fingerprint, the Fingerprint doesn't need to stay in the background.



Hope i'm clear and thanks for any answer.










share|improve this question


















  • 2





    When you re-render a page and if you aren’t returning your unwanted component in render method, that will not be rendered. So you can simply use whatever method you are currently trying keeping in mine not to return unwanted element.

    – Samitha Nanayakkara
    Nov 22 '18 at 13:29
















0















I configured my Navigators as follows:



App.js



const AppStack = createStackNavigator ({Home: HomeScreen});
const AuthStack = createStackNavigator({ Login: Login},{ headerMode: 'none' });

export default createSwitchNavigator(
{
App: AppStack,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}
);


The Login can be three different component: Username/Password, Pincode, Fingerprint. In the Login component i use conditional rendering for show te right screen:



Login.js



if(){
return(<Fingerprint navigation={this.props.navigation}}/>)
} else if (){
return(<Password navigation={this.props.navigation}/>)
} else if (){
return(<Pincode navigation={this.props.navigation}}/>)
}


When i want to switch between this components i used setState() so the Login.js can re-render and show the right screen based on the if-else if statement in the code section above.



Now i my question, is this the right implementation with performance in mind? For example when I wanna show Pincode instead of Fingerprint, the Fingerprint doesn't need to stay in the background.



Hope i'm clear and thanks for any answer.










share|improve this question


















  • 2





    When you re-render a page and if you aren’t returning your unwanted component in render method, that will not be rendered. So you can simply use whatever method you are currently trying keeping in mine not to return unwanted element.

    – Samitha Nanayakkara
    Nov 22 '18 at 13:29














0












0








0








I configured my Navigators as follows:



App.js



const AppStack = createStackNavigator ({Home: HomeScreen});
const AuthStack = createStackNavigator({ Login: Login},{ headerMode: 'none' });

export default createSwitchNavigator(
{
App: AppStack,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}
);


The Login can be three different component: Username/Password, Pincode, Fingerprint. In the Login component i use conditional rendering for show te right screen:



Login.js



if(){
return(<Fingerprint navigation={this.props.navigation}}/>)
} else if (){
return(<Password navigation={this.props.navigation}/>)
} else if (){
return(<Pincode navigation={this.props.navigation}}/>)
}


When i want to switch between this components i used setState() so the Login.js can re-render and show the right screen based on the if-else if statement in the code section above.



Now i my question, is this the right implementation with performance in mind? For example when I wanna show Pincode instead of Fingerprint, the Fingerprint doesn't need to stay in the background.



Hope i'm clear and thanks for any answer.










share|improve this question














I configured my Navigators as follows:



App.js



const AppStack = createStackNavigator ({Home: HomeScreen});
const AuthStack = createStackNavigator({ Login: Login},{ headerMode: 'none' });

export default createSwitchNavigator(
{
App: AppStack,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}
);


The Login can be three different component: Username/Password, Pincode, Fingerprint. In the Login component i use conditional rendering for show te right screen:



Login.js



if(){
return(<Fingerprint navigation={this.props.navigation}}/>)
} else if (){
return(<Password navigation={this.props.navigation}/>)
} else if (){
return(<Pincode navigation={this.props.navigation}}/>)
}


When i want to switch between this components i used setState() so the Login.js can re-render and show the right screen based on the if-else if statement in the code section above.



Now i my question, is this the right implementation with performance in mind? For example when I wanna show Pincode instead of Fingerprint, the Fingerprint doesn't need to stay in the background.



Hope i'm clear and thanks for any answer.







reactjs react-native react-navigation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 12:05









YakalentYakalent

227314




227314








  • 2





    When you re-render a page and if you aren’t returning your unwanted component in render method, that will not be rendered. So you can simply use whatever method you are currently trying keeping in mine not to return unwanted element.

    – Samitha Nanayakkara
    Nov 22 '18 at 13:29














  • 2





    When you re-render a page and if you aren’t returning your unwanted component in render method, that will not be rendered. So you can simply use whatever method you are currently trying keeping in mine not to return unwanted element.

    – Samitha Nanayakkara
    Nov 22 '18 at 13:29








2




2





When you re-render a page and if you aren’t returning your unwanted component in render method, that will not be rendered. So you can simply use whatever method you are currently trying keeping in mine not to return unwanted element.

– Samitha Nanayakkara
Nov 22 '18 at 13:29





When you re-render a page and if you aren’t returning your unwanted component in render method, that will not be rendered. So you can simply use whatever method you are currently trying keeping in mine not to return unwanted element.

– Samitha Nanayakkara
Nov 22 '18 at 13:29












2 Answers
2






active

oldest

votes


















1















when I wanna show Pincode instead of Fingerprint, the Fingerprint
doesn't need to stay in the background.




It won't stay in the background. You can try it yourself, it will be fun. Try writing the following methods in each Component class



class Fingerprint extends Component {
componentDidMount() {
console.log("Fingerprint mounted");
}
componentWillUnmount() {
console.log("Fingerprint unmounted");
}
render() {
...
}
}


And hopefully you will be able to appreciate what React does under the hood.






share|improve this answer































    0














    You could always use a switch called from render?



    returnComponent(identifier){
    switch(identifier){
    case 'fingerprint':
    return <Fingerprint navigation={this.props.navigation}}/>
    break;
    case 'password':
    return <Password navigation={this.props.navigation}/>
    break;
    case 'pin':
    return <Pincode navigation={this.props.navigation}}/>
    break;
    default:
    return null;
    break;
    }
    }
    render(){
    const {identifier} = this.props
    return (
    <div>
    {this.returnComponent(identifier)}
    </div>
    );
    }





    share|improve this answer
























    • Thanks for the answer, but what happens when i switch between this component in the background?

      – Yakalent
      Nov 22 '18 at 12:30











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430647%2freact-navigation-authentation-flow%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1















    when I wanna show Pincode instead of Fingerprint, the Fingerprint
    doesn't need to stay in the background.




    It won't stay in the background. You can try it yourself, it will be fun. Try writing the following methods in each Component class



    class Fingerprint extends Component {
    componentDidMount() {
    console.log("Fingerprint mounted");
    }
    componentWillUnmount() {
    console.log("Fingerprint unmounted");
    }
    render() {
    ...
    }
    }


    And hopefully you will be able to appreciate what React does under the hood.






    share|improve this answer




























      1















      when I wanna show Pincode instead of Fingerprint, the Fingerprint
      doesn't need to stay in the background.




      It won't stay in the background. You can try it yourself, it will be fun. Try writing the following methods in each Component class



      class Fingerprint extends Component {
      componentDidMount() {
      console.log("Fingerprint mounted");
      }
      componentWillUnmount() {
      console.log("Fingerprint unmounted");
      }
      render() {
      ...
      }
      }


      And hopefully you will be able to appreciate what React does under the hood.






      share|improve this answer


























        1












        1








        1








        when I wanna show Pincode instead of Fingerprint, the Fingerprint
        doesn't need to stay in the background.




        It won't stay in the background. You can try it yourself, it will be fun. Try writing the following methods in each Component class



        class Fingerprint extends Component {
        componentDidMount() {
        console.log("Fingerprint mounted");
        }
        componentWillUnmount() {
        console.log("Fingerprint unmounted");
        }
        render() {
        ...
        }
        }


        And hopefully you will be able to appreciate what React does under the hood.






        share|improve this answer














        when I wanna show Pincode instead of Fingerprint, the Fingerprint
        doesn't need to stay in the background.




        It won't stay in the background. You can try it yourself, it will be fun. Try writing the following methods in each Component class



        class Fingerprint extends Component {
        componentDidMount() {
        console.log("Fingerprint mounted");
        }
        componentWillUnmount() {
        console.log("Fingerprint unmounted");
        }
        render() {
        ...
        }
        }


        And hopefully you will be able to appreciate what React does under the hood.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 15:27









        Murtaza RajaMurtaza Raja

        7218




        7218

























            0














            You could always use a switch called from render?



            returnComponent(identifier){
            switch(identifier){
            case 'fingerprint':
            return <Fingerprint navigation={this.props.navigation}}/>
            break;
            case 'password':
            return <Password navigation={this.props.navigation}/>
            break;
            case 'pin':
            return <Pincode navigation={this.props.navigation}}/>
            break;
            default:
            return null;
            break;
            }
            }
            render(){
            const {identifier} = this.props
            return (
            <div>
            {this.returnComponent(identifier)}
            </div>
            );
            }





            share|improve this answer
























            • Thanks for the answer, but what happens when i switch between this component in the background?

              – Yakalent
              Nov 22 '18 at 12:30
















            0














            You could always use a switch called from render?



            returnComponent(identifier){
            switch(identifier){
            case 'fingerprint':
            return <Fingerprint navigation={this.props.navigation}}/>
            break;
            case 'password':
            return <Password navigation={this.props.navigation}/>
            break;
            case 'pin':
            return <Pincode navigation={this.props.navigation}}/>
            break;
            default:
            return null;
            break;
            }
            }
            render(){
            const {identifier} = this.props
            return (
            <div>
            {this.returnComponent(identifier)}
            </div>
            );
            }





            share|improve this answer
























            • Thanks for the answer, but what happens when i switch between this component in the background?

              – Yakalent
              Nov 22 '18 at 12:30














            0












            0








            0







            You could always use a switch called from render?



            returnComponent(identifier){
            switch(identifier){
            case 'fingerprint':
            return <Fingerprint navigation={this.props.navigation}}/>
            break;
            case 'password':
            return <Password navigation={this.props.navigation}/>
            break;
            case 'pin':
            return <Pincode navigation={this.props.navigation}}/>
            break;
            default:
            return null;
            break;
            }
            }
            render(){
            const {identifier} = this.props
            return (
            <div>
            {this.returnComponent(identifier)}
            </div>
            );
            }





            share|improve this answer













            You could always use a switch called from render?



            returnComponent(identifier){
            switch(identifier){
            case 'fingerprint':
            return <Fingerprint navigation={this.props.navigation}}/>
            break;
            case 'password':
            return <Password navigation={this.props.navigation}/>
            break;
            case 'pin':
            return <Pincode navigation={this.props.navigation}}/>
            break;
            default:
            return null;
            break;
            }
            }
            render(){
            const {identifier} = this.props
            return (
            <div>
            {this.returnComponent(identifier)}
            </div>
            );
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 12:21









            Luke WalkerLuke Walker

            27114




            27114













            • Thanks for the answer, but what happens when i switch between this component in the background?

              – Yakalent
              Nov 22 '18 at 12:30



















            • Thanks for the answer, but what happens when i switch between this component in the background?

              – Yakalent
              Nov 22 '18 at 12:30

















            Thanks for the answer, but what happens when i switch between this component in the background?

            – Yakalent
            Nov 22 '18 at 12:30





            Thanks for the answer, but what happens when i switch between this component in the background?

            – Yakalent
            Nov 22 '18 at 12:30


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430647%2freact-navigation-authentation-flow%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen