React Navigation Authentation Flow
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
add a comment |
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
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
add a comment |
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
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
reactjs react-native react-navigation
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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>
);
}
Thanks for the answer, but what happens when i switch between this component in the background?
– Yakalent
Nov 22 '18 at 12:30
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 22 '18 at 15:27
Murtaza RajaMurtaza Raja
7218
7218
add a comment |
add a comment |
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>
);
}
Thanks for the answer, but what happens when i switch between this component in the background?
– Yakalent
Nov 22 '18 at 12:30
add a comment |
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>
);
}
Thanks for the answer, but what happens when i switch between this component in the background?
– Yakalent
Nov 22 '18 at 12:30
add a comment |
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>
);
}
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>
);
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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