forked from riccardo-forina/use-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyRoute.stories.tsx
27 lines (25 loc) · 885 Bytes
/
LazyRoute.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Button } from '@patternfly/react-core';
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { MemoryRouter } from 'react-router';
import { LazyRoute } from './LazyRoute';
const stories = storiesOf('Utils', module);
stories.add('LazyRoute', () => {
const ItWorks = () => <div>It works</div>;
let getComponentResolve: any;
const getComponentPromise = new Promise<{ default: React.ComponentType }>(
resolve => {
getComponentResolve = resolve;
}
);
const getComponent = () => getComponentPromise;
const resolveComponent = () => getComponentResolve({ default: ItWorks });
return (
<MemoryRouter>
<LazyRoute getComponent={getComponent}>
{({ component: Component }) => <Component />}
</LazyRoute>
<Button onClick={resolveComponent}>Resolve the promise</Button>
</MemoryRouter>
);
});