Search code examples
javascriptreact-nativeasync-awaitasyncstorage

How to change app theme using a promise with react native AsyncStorage?


i create 2 themes in my react native project and works good.

I just need to change lightMode to darkMode.

enter image description here To use this theme i just need to import and use: enter image description here

but now, i need to import lightMode dynamic, i can just use a switch:

enter image description here

but how i can do this, with asyncStorage? Because i need to work with promises:

enter image description here

enter image description here

enter image description here


Solution

  • For such situations,

    You need to load all those data into memory from storage(AsyncStorage in this case) right after the app starts.

    You can do this while you show the splash screen.