1.8.3 • Published 3 months ago

@rpldy/retry-hooks v1.8.3

Weekly downloads
894
License
MIT
Repository
github
Last release
3 months ago

This package exposes useful hooks for the @rpldy/retry package which adds upload retry capabilities to the uploader.

It makes it easy to use retry from a React UI application.

The best place to get started is at our: React-Uploady Documentation Website

Installation

#Yarn: 
   $ yarn add @rpldy/uploady @rpldy/retry-hooks

#NPM:
   $ npm i @rpldy/uploady @rpldy/retry-hooks

Enabling Retry

To enable retries for your Uploady instance, you need to use the provided (uploader enhancer): retryEnhancer.

import Uploady from "@rpldy/uploady";
import retryEnhancer from "@rpldy/retry-hooks";
import UploadButton from "@rpldy/upload-button";

const App = () => {
    return <Uploady 
              destination={{ url: "my-server.com/upload" }}
              enhancer={retryEnhancer}
           >
              <UploadButton/>
           </Uploady>;               
};

This will add the retry capability for failed uploads.

See below how to use hooks in order to trigger a retry

Events

Retry related events.

Registering to handle events can be done using the uploader's on() and once() methods. Unregistering can be done using off() or by the return value of both on() and once().

RETRY_EVENT

Triggered when files are re-added to the queue for retry.

  • Parameters: ({ uploads: BatchItem[], options?: UploadOptions })

uploads is an array of batch items. options are the (optional) upload options that are passed to the retry call

Hooks

useRetry

Returns a retry function.

When called without a parameter, will attempt retry all failed uploads. When called with a (id) parameter, will attempt retry for the failed batch-item identified by the id.

import React from "react";
import { useRetry } from "@rpldy/retry-hooks";

const MyComponent = ( ) => {
    const retry = useRetry();

    const onClick = () => {
        retry("i-123");
    };

    return <button onClick={onClick}>retry item</button>;
};

useBatchRetry

Returns a batch retry function.

When called with a batch id, will attempt retry for all failed items in that batch.

import React from "react";
import { useBatchRetry } from "@rpldy/retry-hooks";

const MyComponent = ( ) => {
    const retryBatch = useBatchRetry();

    const onClick = () => {
        retryBatch("b-123");
    };

    return <button onClick={onClick}>retry batch</button>;
};

useRetryListener

Called when items are sent to be re-uploaded (retry)

see RETRY_EVENT

import React from "react";
import { useRetryListener } from "@rpldy/retry-hooks";

const MyComponent = ( ) => {
    
    useRetryListener(({ items }) => {
        console.log("##### RETRY EVENT - retrying items: ", items);
    });

    return <div/>;
};
1.8.2

4 months ago

1.8.3

3 months ago

1.8.1

6 months ago

1.8.0

9 months ago

1.8.0-rc.0

9 months ago

1.7.1

11 months ago

1.7.0

11 months ago

1.7.0-rc.1

11 months ago

1.7.0-rc.0

12 months ago

1.6.1

1 year ago

1.6.0

1 year ago

1.6.0-rc.0

1 year ago

1.5.0-rc.0

1 year ago

1.5.0-rc.1

1 year ago

1.5.0-rc.2

1 year ago

1.5.0-rc.3

1 year ago

1.5.0-rc.4

1 year ago

1.5.0-rc.5

1 year ago

1.5.0

1 year ago

1.6.1-rc.2

1 year ago

1.6.1-rc.0

1 year ago

1.6.1-rc.1

1 year ago

1.4.2-alpha.0

2 years ago

1.4.1

2 years ago

1.4.1-rc.0

2 years ago

1.4.0

2 years ago

1.4.0-rc.0

2 years ago

1.4.0-rc.1

2 years ago

1.3.1

2 years ago

1.2.0

2 years ago

1.3.0-rc.2

2 years ago

1.3.0-rc.3

2 years ago

1.3.0-rc.0

2 years ago

1.3.0-rc.1

2 years ago

1.3.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.1.0-rc.1

2 years ago

1.1.0-rc.0

2 years ago

1.0.0

2 years ago

0.18.3

3 years ago

0.18.1

3 years ago

0.18.2

3 years ago

0.18.0

3 years ago

0.17.2

3 years ago

0.17.3

3 years ago

0.17.4

3 years ago

0.17.5

3 years ago

0.17.0

3 years ago

0.17.1

3 years ago

0.16.1

3 years ago

0.16.2

3 years ago

0.15.0

3 years ago

0.16.0

3 years ago

0.14.2

3 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.13.6

3 years ago

0.13.5

3 years ago

0.13.4

3 years ago

0.13.3

3 years ago

0.13.1

3 years ago

0.13.2

3 years ago

0.13.0

3 years ago

0.12.1

3 years ago

0.12.0

4 years ago

0.11.5

4 years ago

0.11.6

4 years ago

0.11.4

4 years ago

0.11.2

4 years ago

0.11.3

4 years ago

0.11.3-alpha.0

4 years ago

0.11.2-alpha.0

4 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.12

4 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago