How to display data from AsyncStorage in react-native?

20 views Asked by At

Good day, I am attempting to get and display data from AsyncStorage. The data is being received, when I console log the data it is all there. However, I am unable to display this data as text, for example. Thanks for your help in advance.

This is my getItem function:

      const readProfile = async()=>{
        try{
          const value = await AsyncStorage.getItem('userPro');
          if(value !== null){
            console.log(value)
            setParsedValue [JSON.parse(value)];
            console.log(parsedValue);
            return value;
          }  
        }catch (error){
            console.log("We have an error");
            console.log(error)
        }
    }

Here is the ways in witch I have tried to display the data:

<Text>{value.name}</Text>
<Text>{parsedValue.name}</Text>

I know that the data needs to be parsed(the data is in the form of an object), but I am not sure if I am doing this correctly either.

1

There are 1 answers

0
Shahjahan On

setParsedValue [JSON.parse(value)] should be setParsedValue(JSON.parse(value))