MCPcopy
hub / github.com/jamiebuilds/react-loadable / createLoadableComponent

Function createLoadableComponent

src/index.js:100–248  ·  view source on GitHub ↗
(loadFn, options)

Source from the content-addressed store, hash-verified

98}
99
100function createLoadableComponent(loadFn, options) {
101 if (!options.loading) {
102 throw new Error("react-loadable requires a `loading` component");
103 }
104
105 let opts = Object.assign(
106 {
107 loader: null,
108 loading: null,
109 delay: 200,
110 timeout: null,
111 render: render,
112 webpack: null,
113 modules: null
114 },
115 options
116 );
117
118 let res = null;
119
120 function init() {
121 if (!res) {
122 res = loadFn(opts.loader);
123 }
124 return res.promise;
125 }
126
127 ALL_INITIALIZERS.push(init);
128
129 if (typeof opts.webpack === "function") {
130 READY_INITIALIZERS.push(() => {
131 if (isWebpackReady(opts.webpack)) {
132 return init();
133 }
134 });
135 }
136
137 return class LoadableComponent extends React.Component {
138 constructor(props) {
139 super(props);
140 init();
141
142 this.state = {
143 error: res.error,
144 pastDelay: false,
145 timedOut: false,
146 loading: res.loading,
147 loaded: res.loaded
148 };
149 }
150
151 static contextTypes = {
152 loadable: PropTypes.shape({
153 report: PropTypes.func.isRequired
154 })
155 };
156
157 static preload() {

Callers 2

LoadableFunction · 0.85
LoadableMapFunction · 0.85

Calls 2

isWebpackReadyFunction · 0.85
initFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…