1

I'm trying to render card list from AsyncStorage. What i want to do is get all data from storage and create card list depending on this data. I can see storage data inside function but i cannot return view. Here's what i did.

import {View,AsyncStorage} from "react-native";
import { Container, Header, Content, Card, CardItem, Text, Body, Icon, Fab } 
from "native-base";


export default class extends Component{

 async _retrieveData(){
    const value = await AsyncStorage.getAllKeys();
    return value;
 };

 getAll(){
   this._retrieveData()
     .then(items =>{
       items.map(async (k) => {
         await AsyncStorage.getItem(k).then(ok => {

           var cards = [];

             cards.push(

               <Card key="">
                 <CardItem>
                   <Body>
                     <Text>
                       ok data
                     </Text>
                   </Body>
                 </CardItem>
               </Card>

             )
           return cards;

         });
       });

     })
     .catch(err =>{
       alert(err);
     });
   };


   render(){

       return(
         <Container>
           <Content padder>
           {this.getAll()}
           </Content>
         </Container>
       )
   }
}

1 Answer 1

2

You can't call getAll function inside render method because it needs promise to be resolved.

You can call the same function inside componenDidMount method, save cards to local state and then render that data inside render method.

Sign up to request clarification or add additional context in comments.

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.