Skip to content

Commit

Permalink
Code comments for lazy method
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jan 20, 2019
1 parent e788dc9 commit 02634dd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ const {createElement} = require('react');
const isServer = typeof window === 'undefined';
const fatalPromise = {then: () => {}, _fatal: true};

/**
* Create a lazy-loaded component, to work with `React.Suspense`.
* When returned component is first rendered, it calls `ctor()` which should return a Promise.
* Component throws the Promise.
* Once promise resolves, further renders will render the loaded component.
*
* @param {Function} ctor - Function to call to load component. Must return a Promise.
* @param {Object} [options] - Options object
* @param {boolean} [options.ssr = true] - If falsy then component will not be rendered on server
* @returns {Function} - Lazy component
*/
module.exports = function lazy(ctor, options) {
let noSsr = options ? options.ssr !== undefined && !options.ssr : false;

Expand Down

0 comments on commit 02634dd

Please sign in to comment.