mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Add SuspenseList to react-is (#20874)
This commit also adds explicit index.stable and index.experimental forks to the react-is package so that we can avoid exporting references to SuspenseList in a stable release.
This commit is contained in:
41
packages/react-is/index.experimental.js
Normal file
41
packages/react-is/index.experimental.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
export {
|
||||
isValidElementType,
|
||||
typeOf,
|
||||
ContextConsumer,
|
||||
ContextProvider,
|
||||
Element,
|
||||
ForwardRef,
|
||||
Fragment,
|
||||
Lazy,
|
||||
Memo,
|
||||
Portal,
|
||||
Profiler,
|
||||
StrictMode,
|
||||
Suspense,
|
||||
unstable_SuspenseList,
|
||||
isAsyncMode,
|
||||
isConcurrentMode,
|
||||
isContextConsumer,
|
||||
isContextProvider,
|
||||
isElement,
|
||||
isForwardRef,
|
||||
isFragment,
|
||||
isLazy,
|
||||
isMemo,
|
||||
isPortal,
|
||||
isProfiler,
|
||||
isStrictMode,
|
||||
isSuspense,
|
||||
unstable_isSuspenseList,
|
||||
} from './src/ReactIs';
|
||||
39
packages/react-is/index.stable.js
Normal file
39
packages/react-is/index.stable.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
export {
|
||||
isValidElementType,
|
||||
typeOf,
|
||||
ContextConsumer,
|
||||
ContextProvider,
|
||||
Element,
|
||||
ForwardRef,
|
||||
Fragment,
|
||||
Lazy,
|
||||
Memo,
|
||||
Portal,
|
||||
Profiler,
|
||||
StrictMode,
|
||||
Suspense,
|
||||
isAsyncMode,
|
||||
isConcurrentMode,
|
||||
isContextConsumer,
|
||||
isContextProvider,
|
||||
isElement,
|
||||
isForwardRef,
|
||||
isFragment,
|
||||
isLazy,
|
||||
isMemo,
|
||||
isPortal,
|
||||
isProfiler,
|
||||
isStrictMode,
|
||||
isSuspense,
|
||||
} from './src/ReactIs';
|
||||
4
packages/react-is/src/ReactIs.js
vendored
4
packages/react-is/src/ReactIs.js
vendored
@@ -72,6 +72,7 @@ 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 unstable_SuspenseList = REACT_SUSPENSE_LIST_TYPE;
|
||||
|
||||
export {isValidElementType};
|
||||
|
||||
@@ -142,3 +143,6 @@ export function isStrictMode(object: any) {
|
||||
export function isSuspense(object: any) {
|
||||
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
||||
}
|
||||
export function unstable_isSuspenseList(object: any) {
|
||||
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
|
||||
}
|
||||
|
||||
18
packages/react-is/src/__tests__/ReactIs-test.js
vendored
18
packages/react-is/src/__tests__/ReactIs-test.js
vendored
@@ -186,6 +186,24 @@ describe('ReactIs', () => {
|
||||
expect(ReactIs.isSuspense(<div />)).toBe(false);
|
||||
});
|
||||
|
||||
// @gate experimental
|
||||
it('should identify suspense list', () => {
|
||||
expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true);
|
||||
expect(ReactIs.typeOf(<React.unstable_SuspenseList />)).toBe(
|
||||
ReactIs.unstable_SuspenseList,
|
||||
);
|
||||
expect(
|
||||
ReactIs.unstable_isSuspenseList(<React.unstable_SuspenseList />),
|
||||
).toBe(true);
|
||||
expect(
|
||||
ReactIs.unstable_isSuspenseList({type: ReactIs.unstable_SuspenseList}),
|
||||
).toBe(false);
|
||||
expect(ReactIs.unstable_isSuspenseList('React.unstable_SuspenseList')).toBe(
|
||||
false,
|
||||
);
|
||||
expect(ReactIs.unstable_isSuspenseList(<div />)).toBe(false);
|
||||
});
|
||||
|
||||
it('should identify profile root', () => {
|
||||
expect(ReactIs.isValidElementType(React.Profiler)).toBe(true);
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user