Skip to content

Commit 2aed507

Browse files
authored
Remove React.createFactory (#27798)
`React.createFactory` has been long deprecated. This removes it for the next release.
1 parent 13f3543 commit 2aed507

File tree

9 files changed

+0
-92
lines changed

9 files changed

+0
-92
lines changed

packages/react-is/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ ReactIs.isValidElementType(FunctionComponent); // true
4040
ReactIs.isValidElementType(ForwardRefComponent); // true
4141
ReactIs.isValidElementType(Context.Provider); // true
4242
ReactIs.isValidElementType(Context.Consumer); // true
43-
ReactIs.isValidElementType(React.createFactory("div")); // true
4443
```
4544

4645
### Determining an Element's Type

packages/react-is/src/__tests__/ReactIs-test.js

-12
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ describe('ReactIs', () => {
6767
expect(ReactIs.isValidElementType(MemoComponent)).toEqual(true);
6868
expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true);
6969
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-
}
8270
expect(ReactIs.isValidElementType(React.Fragment)).toEqual(true);
8371
expect(ReactIs.isValidElementType(React.StrictMode)).toEqual(true);
8472
expect(ReactIs.isValidElementType(React.Suspense)).toEqual(true);

packages/react/index.classic.fb.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export {
2020
cloneElement,
2121
createContext,
2222
createElement,
23-
createFactory,
2423
createRef,
2524
use,
2625
forwardRef,

packages/react/index.experimental.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export {
2020
cloneElement,
2121
createContext,
2222
createElement,
23-
createFactory,
2423
createRef,
2524
use,
2625
forwardRef,

packages/react/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export {
4141
cloneElement,
4242
createContext,
4343
createElement,
44-
createFactory,
4544
createRef,
4645
use,
4746
forwardRef,

packages/react/index.stable.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export {
2020
cloneElement,
2121
createContext,
2222
createElement,
23-
createFactory,
2423
createRef,
2524
use,
2625
forwardRef,

packages/react/src/ReactClient.js

-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {createRef} from './ReactCreateRef';
2727
import {forEach, map, count, toArray, only} from './ReactChildren';
2828
import {
2929
createElement,
30-
createFactory,
3130
cloneElement,
3231
isValidElement,
3332
} from './jsx/ReactJSXElement';
@@ -62,7 +61,6 @@ import {
6261
useOptimistic,
6362
useActionState,
6463
} from './ReactHooks';
65-
6664
import ReactSharedInternals from './ReactSharedInternalsClient';
6765
import {startTransition} from './ReactStartTransition';
6866
import {act} from './ReactAct';
@@ -111,8 +109,6 @@ export {
111109
isValidElement,
112110
ReactVersion as version,
113111
ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
114-
// Deprecated behind disableCreateFactory
115-
createFactory,
116112
// Concurrent Mode
117113
useTransition,
118114
startTransition,

packages/react/src/__tests__/ReactElementValidator-test.internal.js

-28
Original file line numberDiff line numberDiff line change
@@ -331,34 +331,6 @@ describe('ReactElementValidator', () => {
331331
);
332332
});
333333

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-
362334
it('does not warn when using DOM node as children', async () => {
363335
class DOMContainer extends React.Component {
364336
ref;

packages/react/src/jsx/ReactJSXElement.js

-43
Original file line numberDiff line numberDiff line change
@@ -757,49 +757,6 @@ export function createElement(type, config, children) {
757757
return element;
758758
}
759759

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-
803760
export function cloneAndReplaceKey(oldElement, newKey) {
804761
return ReactElement(
805762
oldElement.type,

0 commit comments

Comments
 (0)