Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 893 Bytes

useAsyncRetry.md

File metadata and controls

37 lines (30 loc) · 893 Bytes

useAsyncRetry

Uses useAsync with an additional retry method to easily retry/refresh the async function;

Usage

import {useAsyncRetry} from 'vue-next-use';

const Demo = ({url}) => ({
  setup(){
        const state = useAsyncRetry(async () => {
            const response = await fetch(url);
            const result = await response.text();
            return result;
        }, [url]);

        return () => (
            <div>
                {state.loading
                    ? <div>Loading...</div>
                    : state.error
                        ? <div>Error: {state.error.message}</div>
                        : <div>Value: {state.value}</div>
                }
                {!loading && <button onClick={() => state.retry()}>Start loading</button>}
            </div>
        );
    }
});

Reference

useAsyncRetry(fn, args?: any[]);