I
I
Ilya2019-03-14 04:57:04
React Native
Ilya, 2019-03-14 04:57:04

How to render different pages in React Native?

I have a token stored in AsyncStorage.
How can I make it so that if token === null one would be rendered, and if there is something in it, another would be rendered?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Panteleev, 2019-03-14
@ynizhenie

render() {
let token = null;
AsyncStorage.getItem('token')
    .then((value) => {
      if(value !== null) {
        token = value;
      }
 });

  return (
    {token !== null ? (
        <View>
        	<Text>Токен есть</Text>
        </View>
    ) : (
        <View>
        	<Text>Токена нет</Text>
        </View>
    )}
  )
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question