Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp.element - export lazy and Suspense #14412

Merged
merged 20 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 10 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
16 changes: 16 additions & 0 deletions packages/element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ Checks if an object is a valid WPElement

`boolean`: true if objectToTest is a valid WPElement and false otherwise.

### lazy

[src/index.js#L1-L1](src/index.js#L1-L1)

The React.lazy function lets you render a dynamic import as a regular component.

**Parameters**

- **loadFunction** `function`: A function that must call a dynamic import(). This must return a Promise which resolves to a module with a default export containing a React component.

### RawHTML

[src/index.js#L5-L5](src/index.js#L5-L5)
Expand Down Expand Up @@ -289,6 +299,12 @@ Serializes a React element to string.

Component that activates additional checks and warnings for its descendants.

### Suspense

[src/index.js#L1-L1](src/index.js#L1-L1)

Component to do code-splitting by wrapping a dynamic import.

### switchChildrenNodeName

[src/index.js#L1-L1](src/index.js#L1-L1)
Expand Down
15 changes: 15 additions & 0 deletions packages/element/src/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
useImperativeHandle,
useLayoutEffect,
useDebugValue,
lazy,
Suspense,
} from 'react';
import { isString } from 'lodash';

Expand Down Expand Up @@ -109,6 +111,19 @@ export { isValidElement };
*/
export { StrictMode };

/**
* The React.lazy function lets you render a dynamic import as a regular component.
*
* @param {function} loadFunction A function that must call a dynamic import(). This must return a Promise which
* resolves to a module with a default export containing a React component.
*/
export { lazy };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nosolosw had a good idea to add the link to the original function description in React docs. See #14425.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, i updated my PR to use this format in bb22466


/**
* Component to do code-splitting by wrapping a dynamic import.
*/
export { Suspense };

/**
* Make React Hooks available
*/
Expand Down