Skip to content

Commit baa14c7

Browse files
committed
Remove React.createFactory
1 parent aba93ac commit baa14c7

File tree

6 files changed

+0
-96
lines changed

6 files changed

+0
-96
lines changed

packages/react-is/README.md

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 12 deletions
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/src/React.js

Lines changed: 0 additions & 7 deletions
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 as createElementProd,
30-
createFactory as createFactoryProd,
3130
cloneElement as cloneElementProd,
3231
isValidElement,
3332
} from './ReactElement';
@@ -63,7 +62,6 @@ import {
6362
} from './ReactHooks';
6463
import {
6564
createElementWithValidation,
66-
createFactoryWithValidation,
6765
cloneElementWithValidation,
6866
} from './ReactElementValidator';
6967
import {createServerContext} from './ReactServerContext';
@@ -78,9 +76,6 @@ const createElement: any = __DEV__
7876
const cloneElement: any = __DEV__
7977
? cloneElementWithValidation
8078
: cloneElementProd;
81-
const createFactory: any = __DEV__
82-
? createFactoryWithValidation
83-
: createFactoryProd;
8479

8580
const Children = {
8681
map,
@@ -126,8 +121,6 @@ export {
126121
isValidElement,
127122
ReactVersion as version,
128123
ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
129-
// Deprecated behind disableCreateFactory
130-
createFactory,
131124
// Concurrent Mode
132125
useTransition,
133126
startTransition,

packages/react/src/ReactElement.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -450,21 +450,6 @@ export function createElement(type, config, children) {
450450
);
451451
}
452452

453-
/**
454-
* Return a function that produces ReactElements of a given type.
455-
* See https://reactjs.org/docs/react-api.html#createfactory
456-
*/
457-
export function createFactory(type) {
458-
const factory = createElement.bind(null, type);
459-
// Expose the type on the factory and the prototype so that it can be
460-
// easily accessed on elements. E.g. `<Foo />.type === Foo`.
461-
// This should not be named `constructor` since this may not be the function
462-
// that created the element, and it may not even be a constructor.
463-
// Legacy hook: remove it
464-
factory.type = type;
465-
return factory;
466-
}
467-
468453
export function cloneAndReplaceKey(oldElement, newKey) {
469454
const newElement = ReactElement(
470455
oldElement.type,

packages/react/src/ReactElementValidator.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -508,39 +508,6 @@ export function createElementWithValidation(type, props, children) {
508508
return element;
509509
}
510510

511-
let didWarnAboutDeprecatedCreateFactory = false;
512-
513-
export function createFactoryWithValidation(type) {
514-
const validatedFactory = createElementWithValidation.bind(null, type);
515-
validatedFactory.type = type;
516-
if (__DEV__) {
517-
if (!didWarnAboutDeprecatedCreateFactory) {
518-
didWarnAboutDeprecatedCreateFactory = true;
519-
console.warn(
520-
'React.createFactory() is deprecated and will be removed in ' +
521-
'a future major release. Consider using JSX ' +
522-
'or use React.createElement() directly instead.',
523-
);
524-
}
525-
// Legacy hook: remove it
526-
Object.defineProperty(validatedFactory, 'type', {
527-
enumerable: false,
528-
get: function () {
529-
console.warn(
530-
'Factory.type is deprecated. Access the class directly ' +
531-
'before passing it to createFactory.',
532-
);
533-
Object.defineProperty(this, 'type', {
534-
value: type,
535-
});
536-
return type;
537-
},
538-
});
539-
}
540-
541-
return validatedFactory;
542-
}
543-
544511
export function cloneElementWithValidation(element, props, children) {
545512
const newElement = cloneElement.apply(this, arguments);
546513
for (let i = 2; i < arguments.length; i++) {

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -438,34 +438,6 @@ describe('ReactElementValidator', () => {
438438
);
439439
});
440440

441-
if (!__EXPERIMENTAL__) {
442-
it('should warn when accessing .type on an element factory', () => {
443-
function TestComponent() {
444-
return <div />;
445-
}
446-
447-
let TestFactory;
448-
449-
expect(() => {
450-
TestFactory = React.createFactory(TestComponent);
451-
}).toWarnDev(
452-
'Warning: React.createFactory() is deprecated and will be removed in a ' +
453-
'future major release. Consider using JSX or use React.createElement() ' +
454-
'directly instead.',
455-
{withoutStack: true},
456-
);
457-
458-
expect(() => TestFactory.type).toWarnDev(
459-
'Warning: Factory.type is deprecated. Access the class directly before ' +
460-
'passing it to createFactory.',
461-
{withoutStack: true},
462-
);
463-
464-
// Warn once, not again
465-
expect(TestFactory.type).toBe(TestComponent);
466-
});
467-
}
468-
469441
it('does not warn when using DOM node as children', () => {
470442
class DOMContainer extends React.Component {
471443
render() {

0 commit comments

Comments
 (0)