Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,17 @@ Loadable({
});
```

#### `opts.displayName`

Display name for the returned component. Defaults to `LoadableComponent`.

```js
Loadable({
displayName: 'MyLoadableComponent',
loader: () => import('./Bar'),
});
```

#### `opts.delay`

Time to wait (in milliseconds) before passing
Expand Down
21 changes: 19 additions & 2 deletions __tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ test('loadable map error', async () => {
expect(component.toJSON()).toMatchSnapshot(); // success
});

test('display name', async () => {
let LoadableMyComponent = Loadable({
displayName: 'ComponentWith200Delay',
loader: createLoader(200, () => MyComponent),
loading: MyLoadingComponent
});

expect(LoadableMyComponent.displayName).toEqual('ComponentWith200Delay');

LoadableMyComponent = Loadable({
loader: createLoader(200, () => MyComponent),
loading: MyLoadingComponent
});

expect(LoadableMyComponent.displayName).toEqual('LoadableComponent');
});

describe('preloadReady', () => {
beforeEach(() => {
global.__webpack_modules__ = { 1: true, 2: true };
Expand Down Expand Up @@ -272,9 +289,9 @@ describe('preloadReady', () => {
delay: 0,
timeout: 200,
});

let loadingComponent = renderer.create(<LoadableMyComponent prop="foo" />);

expect(loadingComponent.toJSON()).toMatchSnapshot(); // loading
});
});
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function createLoadableComponent(loadFn, options) {
});
}

return class LoadableComponent extends React.Component {
class LoadableComponent extends React.Component {
constructor(props) {
super(props);
init();
Expand Down Expand Up @@ -254,6 +254,10 @@ function createLoadableComponent(loadFn, options) {
}
}
};

LoadableComponent.displayName = opts.displayName || 'LoadableComponent';

return LoadableComponent;
}

function Loadable(opts) {
Expand Down