3 thoughts on “AsyncStorage cannot work on synchronous way.

  1. @max-mykhailenko

    I do it this way,

    1. dispatch an action LOAD_SAVED_DATA_REQUEST.
    2. load the data from AsyncStorage when I receive this action
    3. dispatch an action LOAD_SAVED_DATA with the payload as the new state when loading succeeds, or LOAD_SAVED_DATA_FAILED when loading fails
    4. when I get LOAD_SAVED_DATA action with new state, I replace the current state with the new state in my reducer

    You can also have a state isRestoringData or something to indicate if you’re loading the data, so that you can show a splash screen or spinner, and then set it to false when you get LOAD_SAVED_DATA. Usually it is fast enough that I just return null in my component instead of showing a spinner.

Comments are closed.

1 thought on “AsyncStorage cannot work on synchronous way.

  1. @max-mykhailenko

    I do it this way,

    1. dispatch an action LOAD_SAVED_DATA_REQUEST.
    2. load the data from AsyncStorage when I receive this action
    3. dispatch an action LOAD_SAVED_DATA with the payload as the new state when loading succeeds, or LOAD_SAVED_DATA_FAILED when loading fails
    4. when I get LOAD_SAVED_DATA action with new state, I replace the current state with the new state in my reducer

    You can also have a state isRestoringData or something to indicate if you’re loading the data, so that you can show a splash screen or spinner, and then set it to false when you get LOAD_SAVED_DATA. Usually it is fast enough that I just return null in my component instead of showing a spinner.

Comments are closed.