Skip to content

Commit

Permalink
Add SuspenseList to react-is
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Feb 24, 2021
1 parent 4190a34 commit e523b27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export const Portal = REACT_PORTAL_TYPE;
export const Profiler = REACT_PROFILER_TYPE;
export const StrictMode = REACT_STRICT_MODE_TYPE;
export const Suspense = REACT_SUSPENSE_TYPE;
export const SuspenseList = __EXPERIMENTAL__
? REACT_SUSPENSE_LIST_TYPE
: undefined;

export {isValidElementType};

Expand Down Expand Up @@ -142,3 +145,10 @@ export function isStrictMode(object: any) {
export function isSuspense(object: any) {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
export function isSuspenseList(object: any) {
if (__EXPERIMENTAL__) {
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
} else {
return false;
}
}
10 changes: 10 additions & 0 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ describe('ReactIs', () => {
expect(ReactIs.isSuspense(<div />)).toBe(false);
});

// @gate experimental
it('should identify suspense list', () => {
expect(ReactIs.isValidElementType(React.SuspenseList)).toBe(true);
expect(ReactIs.typeOf(<React.SuspenseList />)).toBe(ReactIs.SuspenseList);
expect(ReactIs.isSuspenseList(<React.SuspenseList />)).toBe(true);
expect(ReactIs.isSuspenseList({type: ReactIs.SuspenseList})).toBe(false);
expect(ReactIs.isSuspenseList('React.SuspenseList')).toBe(false);
expect(ReactIs.isSuspenseList(<div />)).toBe(false);
});

it('should identify profile root', () => {
expect(ReactIs.isValidElementType(React.Profiler)).toBe(true);
expect(
Expand Down

0 comments on commit e523b27

Please sign in to comment.