@samitouri / QOS-React / commits / 2aed507a76

Remove React.createFactory (#27798)

`React.createFactory` has been long deprecated. This removes it for the next release.

Jan Kassens committed Mar 29, 2024 at 16:29 UTC 2aed507a76a0b1524426c398897cbe47d80c51e5
9 files changed -92
packages/react-is/README.md
-1
@@ -40,7 +40,6 @@ ReactIs.isValidElementType(FunctionComponent); // true
40 ReactIs.isValidElementType(ForwardRefComponent); // true
41 ReactIs.isValidElementType(Context.Provider); // true
42 ReactIs.isValidElementType(Context.Consumer); // true
43 -ReactIs.isValidElementType(React.createFactory("div")); // true
43 ```
44
45 ### Determining an Element's Type
packages/react-is/src/__tests__/ReactIs-test.js
-12
@@ -67,18 +67,6 @@ describe('ReactIs', () => {
67 expect(ReactIs.isValidElementType(MemoComponent)).toEqual(true);
68 expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true);
69 expect(ReactIs.isValidElementType(Context.Consumer)).toEqual(true);
70 - if (!__EXPERIMENTAL__) {
71 - let factory;
72 - expect(() => {
73 - factory = React.createFactory('div');
74 - }).toWarnDev(
75 - 'Warning: React.createFactory() is deprecated and will be removed in a ' +
76 - 'future major release. Consider using JSX or use React.createElement() ' +
77 - 'directly instead.',
78 - {withoutStack: true},
79 - );
80 - expect(ReactIs.isValidElementType(factory)).toEqual(true);
81 - }
70 expect(ReactIs.isValidElementType(React.Fragment)).toEqual(true);
71 expect(ReactIs.isValidElementType(React.StrictMode)).toEqual(true);
72 expect(ReactIs.isValidElementType(React.Suspense)).toEqual(true);
packages/react/index.classic.fb.js
-1
@@ -20,7 +20,6 @@ export {
20 cloneElement,
21 createContext,
22 createElement,
23 - createFactory,
23 createRef,
24 use,
25 forwardRef,
packages/react/index.experimental.js
-1
@@ -20,7 +20,6 @@ export {
20 cloneElement,
21 createContext,
22 createElement,
23 - createFactory,
23 createRef,
24 use,
25 forwardRef,
packages/react/index.js
-1
@@ -41,7 +41,6 @@ export {
41 cloneElement,
42 createContext,
43 createElement,
44 - createFactory,
44 createRef,
45 use,
46 forwardRef,
packages/react/index.stable.js
-1
@@ -20,7 +20,6 @@ export {
20 cloneElement,
21 createContext,
22 createElement,
23 - createFactory,
23 createRef,
24 use,
25 forwardRef,
packages/react/src/ReactClient.js
-4
@@ -27,7 +27,6 @@ import {createRef} from './ReactCreateRef';
27 import {forEach, map, count, toArray, only} from './ReactChildren';
28 import {
29 createElement,
30 - createFactory,
30 cloneElement,
31 isValidElement,
32 } from './jsx/ReactJSXElement';
@@ -62,7 +61,6 @@ import {
61 useOptimistic,
62 useActionState,
63 } from './ReactHooks';
65 -
64 import ReactSharedInternals from './ReactSharedInternalsClient';
65 import {startTransition} from './ReactStartTransition';
66 import {act} from './ReactAct';
@@ -111,8 +109,6 @@ export {
109 isValidElement,
110 ReactVersion as version,
111 ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
114 - // Deprecated behind disableCreateFactory
115 - createFactory,
112 // Concurrent Mode
113 useTransition,
114 startTransition,
packages/react/src/__tests__/ReactElementValidator-test.internal.js
-28
@@ -331,34 +331,6 @@ describe('ReactElementValidator', () => {
331 );
332 });
333
334 - if (!__EXPERIMENTAL__) {
335 - it('should warn when accessing .type on an element factory', () => {
336 - function TestComponent() {
337 - return <div />;
338 - }
339 -
340 - let TestFactory;
341 -
342 - expect(() => {
343 - TestFactory = React.createFactory(TestComponent);
344 - }).toWarnDev(
345 - 'Warning: React.createFactory() is deprecated and will be removed in a ' +
346 - 'future major release. Consider using JSX or use React.createElement() ' +
347 - 'directly instead.',
348 - {withoutStack: true},
349 - );
350 -
351 - expect(() => TestFactory.type).toWarnDev(
352 - 'Warning: Factory.type is deprecated. Access the class directly before ' +
353 - 'passing it to createFactory.',
354 - {withoutStack: true},
355 - );
356 -
357 - // Warn once, not again
358 - expect(TestFactory.type).toBe(TestComponent);
359 - });
360 - }
361 -
334 it('does not warn when using DOM node as children', async () => {
335 class DOMContainer extends React.Component {
336 ref;
packages/react/src/jsx/ReactJSXElement.js
-43
@@ -757,49 +757,6 @@ export function createElement(type, config, children) {
757 return element;
758 }
759
760 -let didWarnAboutDeprecatedCreateFactory = false;
761 -
762 -/**
763 - * Return a function that produces ReactElements of a given type.
764 - * See https://reactjs.org/docs/react-api.html#createfactory
765 - */
766 -export function createFactory(type) {
767 - const factory = createElement.bind(null, type);
768 - // Expose the type on the factory and the prototype so that it can be
769 - // easily accessed on elements. E.g. `<Foo />.type === Foo`.
770 - // This should not be named `constructor` since this may not be the function
771 - // that created the element, and it may not even be a constructor.
772 - // Legacy hook: remove it
773 - factory.type = type;
774 -
775 - if (__DEV__) {
776 - if (!didWarnAboutDeprecatedCreateFactory) {
777 - didWarnAboutDeprecatedCreateFactory = true;
778 - console.warn(
779 - 'React.createFactory() is deprecated and will be removed in ' +
780 - 'a future major release. Consider using JSX ' +
781 - 'or use React.createElement() directly instead.',
782 - );
783 - }
784 - // Legacy hook: remove it
785 - Object.defineProperty(factory, 'type', {
786 - enumerable: false,
787 - get: function () {
788 - console.warn(
789 - 'Factory.type is deprecated. Access the class directly ' +
790 - 'before passing it to createFactory.',
791 - );
792 - Object.defineProperty(this, 'type', {
793 - value: type,
794 - });
795 - return type;
796 - },
797 - });
798 - }
799 -
800 - return factory;
801 -}
802 -
760 export function cloneAndReplaceKey(oldElement, newKey) {
761 return ReactElement(
762 oldElement.type,