How to get value from NativeStorage and save or return you value (see image)

Hello! :smiley:

I’m having difficulty, in what seems SIMPLE …

How do I return and save the value that comes in getItem?

Within the getItem returns the correct value, out comes null.

The image is better to illustrate.

Sorry for my English :frowning:



It is far from simple, and in fact completely impossible. That is the entire point of asynchronous operation. Here is how I break down the various types of asynchronous operation; perhaps it will be useful for you as well.

1 Like

I understood.
I needed to get an “public getUsuarioAtivo” return the value.
So there’s no way?

There’s no way. The best you can do is return a Promise from getUsuarioAtivo() and whoever calls it must wrap in a then clause whatever it needs to do with it. That’s the third category described in that other post, and the very first word you type in the body of getUsarioAtivo() should be “return”.

1 Like

You’ll benefit hugely from learning about callback / async / promise type functionality.

Most languages are going that way if they haven’t already :slight_smile: