# react-lazy-retry

> A way to allow users to retry their lazy loaded React components.

Latest version **1.0.0** (published 2019-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-lazy-retry
pnpm add react-lazy-retry
yarn add react-lazy-retry
bun add react-lazy-retry
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-11-05 |
| First published | 2019-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | c-rodg |
| Keywords | react, lazy, retry, lazy loaded, suspense, dynamic |

## Links

- npm: https://www.npmjs.com/package/react-lazy-retry
- Repository: https://github.com/C-Rodg/React-Lazy-Retry
- Homepage: https://github.com/C-Rodg/React-Lazy-Retry#readme
- Issues: https://github.com/C-Rodg/React-Lazy-Retry/issues
- npm.io page: https://npm.io/package/react-lazy-retry

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-11-05

## README

# React Lazy Retry

A way to retry with your lazy-loaded React components.

## Purpose

React.lazy is great, but out-of-the-box if it fails, that's it. This library allows for you to provide users with a way to manually retry to load the lazy-loaded route without requiring them to do a page refresh.

## Implementation Guide

##### 1. Installation

- Yarn:

  `yarn add react-lazy-retry`

- NPM:

  `npm install react-lazy-retry --save`

##### 2. Use

```javascript
import React from 'react';

// Import the component
import RetryableLazy from 'react-lazy-retry';

// Create a component to show while loading (optional)
const LoaderComponent = () => <>Loading...</>;

// Create a component to show when there is an error (optional)
const ErrorRetryComponent = ({ retry }) => (
	<button type="button" onClick={retry}>
		Retry
	</button>
);

// Wrap your async component and provide loading and error components
const MyAsyncComponent = RetryableLazy(() =>
	import('./path/to/component/to/wrap')
);

// Use the component in your application
const App = ({ shouldShowAsyncComponent }) => {
	return (
		<div>
			<h1>My App</h1>
			{shouldShowAsyncComponent && <MyAsyncComponent />}
		</div>
	);
};
```

## API

| Argument Number | Type              | Default                                  | Description                                                                                                                                                                                           |
| :-------------- | :---------------- | :--------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1               | `Promise`         | None                                     | This is a promise for the lazy-loaded component. Typically done using `import`.                                                                                                                       |
| 2               | `React Component` | `<>Loading...</>`                        | This will be shown while the promise for the lazy-loaded component is waiting to resolve. Optional.                                                                                                   |
| 3               | `React Component` | `<button onClick={retry}>Retry</button>` | This is the UI that will be shown to the user if the request for the lazy-loaded component fails. A `retry` function is passed as props, which if called, will request the component again. Optional. |

## Creator

[Curtis](https://curtisrodgers.com/)

---
_Source: https://npm.io/package/react-lazy-retry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
