aksonov / aksonov/react-native-router-flux
How to set initial scene while checking the state of the user is login or not?
- Vorherrschende Sprache
- JavaScript
- Sterne
- 8.9k
- Forks
- 2.1k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### Version
- react-native-router-flux : "^4.0.6"
- react: "16.6.3",
- react-native: "0.58.4",
### Expected behaviour
I am using this module it's working fine. I am storing a login value in **AsyncStorage**. I have 2 screens **Login** and **Home** after login i am checking value in initial screen and it returns home screen initially.
### Actual behaviour
I'm facing an issue with this code it always firstly returns login screen after it returns home screen.
The screen looks like glitches.
### Code
```
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
AsyncStorage,
ActivityIndicator
} from "react-native";
import { Scene, Router, Stack } from "react-native-router-flux";
import Login from "./Src/Initial.js";
import Home from "./Src/Home.js";
type Props = {};
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
initial: true,
homeRouting: false
};
}
async componentWillMount() {
await AsyncStorage.getItem("TokenDetails", (err, result) => {
if (result) {
this.setState({
initial: false,
homeRouting: true
});
} else {
this.setState({
initial: true,
homeRouting: false
});
}
});
}
render() {
return (
{this.state.homeRouting ? (
) : (
)}
);
}
}
```
Here is my screenshot:

Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.