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 6 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
56 changes: 56 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 Expand Up @@ -320,60 +336,100 @@ Removes any mounted element from the target DOM node.

Make React Hooks available

**Parameters**
oandregal marked this conversation as resolved.
Show resolved Hide resolved

- **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.

### useContext

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

Make React Hooks available

**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.

### useDebugValue

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

Make React Hooks available

**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.

### useEffect

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

Make React Hooks available

**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.

### useImperativeHandle

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

Make React Hooks available

**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.

### useLayoutEffect

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

Make React Hooks available

**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.

### useMemo

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

Make React Hooks available

**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.

### useReducer

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

Make React Hooks available

**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.

### useRef

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

Make React Hooks available

**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.

### useState

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

Make React Hooks available

**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.


<!-- END TOKEN(Autogenerated API docs) -->

Expand Down
18 changes: 18 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,8 +111,24 @@ 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
*
* @param {function} loadFunction A function that must call a dynamic import(). This must return a Promise which
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this was meant to be included here?

Copy link
Member Author

@adamsilverstein adamsilverstein Mar 13, 2019

Choose a reason for hiding this comment

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

Right, fixed. Not sure why there are unrelated docs changes even after merging master and running npm run docs:build - am I missing a step?

ps. thanks for reviewing!

Copy link
Member

Choose a reason for hiding this comment

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

running npm run docs:build - am I missing a step?

Can you try it once more? The changes I would have expected with this erroneous DocBlock, but I expect should be largely cleared up if run in the current state of the branch. Would also explain the failing build.

Copy link
Member Author

Choose a reason for hiding this comment

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

grabbed readme from master, then re-ran - changes in 1466b25.

* resolves to a module with a default export containing a React component.
*/
export {
useCallback,
Expand Down