score:0

instead of put code in componentdidmount() try to put it in the constructor() or in the componentwillmount().

i recommend to put that code in the end of the constructor() method because componentwillmount will be deprecated in next versions of react native

score:1

asyncstorage is an asynchronous function as the name suggests, so you have to wait for the response, that's why state has nothing because asyncstorage hasn's finished.

    try {
      const value = await asyncstorage.getitem('@userprofiledocid');
      this.setstate({ userid: value})
    } catch (error) {
      // error retrieving data
    }

and in my honest opinion you should use componentdidmount it is safer but it's my opinion

see this for more opinions

calling setstate in componentwillmount is dangerous because you take a risk in calling setstate while rendering


Related Query

More Query from same tag