-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadable.tsx
42 lines (39 loc) · 1.1 KB
/
loadable.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as React from 'react';
// Typescript throws warnings here about
// signatures here because we can't know
// what will be returned and Loadable's
// types seem not to be configured in a
// way that makes typescript's compiler
// happy. For now you can ignore or can
// use require instead of import.
// Will have to wait until more reliable
// types exist.
//import * as Loadable from 'react-loadable';
const ReactLoadable = require('react-loadable');
export const Loading = (props: any) => {
if (props.error) {
// When the loader has errored
return <div>Error!</div>;
} else if (props.timedOut) {
// When the loader has taken longer than the timeout
return <div>Taking a long time...</div>;
} else if (props.pastDelay) {
// When the loader has taken longer than the delay
return <div>Loading...</div>;
} else {
// When the loader has just started
return null;
}
};
export const LoadablePage = (opts: any) => {
return ReactLoadable(
Object.assign(
{
loading: Loading,
pastDelay: 400,
timeout: 10000,
},
opts
)
);
};