Skip to content

cache hooks data and return when connectivity isn't available #214

Description

@vibern0

A good example is beneficiary data.

Currently, it is implemented on the wallet, caching with the redux state. See here.

But this can be abstracted to the utils also giving support to the web.

Example

// update async storage when a beneficiary or community state changes
// only after the hook data is ready
useEffect(() => {
    if (isReady) {
        import('@react-native-async-storage/async-storage').then(({ default: AsyncStorage}) => {
            AsyncStorage.setItem('@im-utils/cache', JSON.stringify({ beneficiary, community }));
        });
    }
}, [beneficiary, community, isReady]);

// initial load
useEffect(() => {

    import('@react-native-async-storage/async-storage').then(({ default: AsyncStorage}) => {
        AsyncStorage.getItem('@im-utils/cache').then(console.log);
    });

    // (...)
}, [currentBlockNumber]);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions