diff --git a/packages/react-is/README.md b/packages/react-is/README.md index d255977618178..c446e89c6b0fe 100644 --- a/packages/react-is/README.md +++ b/packages/react-is/README.md @@ -40,7 +40,6 @@ ReactIs.isValidElementType(FunctionComponent); // true ReactIs.isValidElementType(ForwardRefComponent); // true ReactIs.isValidElementType(Context.Provider); // true ReactIs.isValidElementType(Context.Consumer); // true -ReactIs.isValidElementType(React.createFactory("div")); // true ``` ### Determining an Element's Type diff --git a/packages/react-is/src/__tests__/ReactIs-test.js b/packages/react-is/src/__tests__/ReactIs-test.js index 5b63eebd529fd..f9d9dc923cc23 100644 --- a/packages/react-is/src/__tests__/ReactIs-test.js +++ b/packages/react-is/src/__tests__/ReactIs-test.js @@ -67,18 +67,6 @@ describe('ReactIs', () => { expect(ReactIs.isValidElementType(MemoComponent)).toEqual(true); expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true); expect(ReactIs.isValidElementType(Context.Consumer)).toEqual(true); - if (!__EXPERIMENTAL__) { - let factory; - expect(() => { - factory = React.createFactory('div'); - }).toWarnDev( - 'Warning: React.createFactory() is deprecated and will be removed in a ' + - 'future major release. Consider using JSX or use React.createElement() ' + - 'directly instead.', - {withoutStack: true}, - ); - expect(ReactIs.isValidElementType(factory)).toEqual(true); - } expect(ReactIs.isValidElementType(React.Fragment)).toEqual(true); expect(ReactIs.isValidElementType(React.StrictMode)).toEqual(true); expect(ReactIs.isValidElementType(React.Suspense)).toEqual(true); diff --git a/packages/react/src/React.js b/packages/react/src/React.js index 5728a2ba50d78..e1b42d64bc81f 100644 --- a/packages/react/src/React.js +++ b/packages/react/src/React.js @@ -27,7 +27,6 @@ import {createRef} from './ReactCreateRef'; import {forEach, map, count, toArray, only} from './ReactChildren'; import { createElement as createElementProd, - createFactory as createFactoryProd, cloneElement as cloneElementProd, isValidElement, } from './ReactElement'; @@ -63,7 +62,6 @@ import { } from './ReactHooks'; import { createElementWithValidation, - createFactoryWithValidation, cloneElementWithValidation, } from './ReactElementValidator'; import {createServerContext} from './ReactServerContext'; @@ -78,9 +76,6 @@ const createElement: any = __DEV__ const cloneElement: any = __DEV__ ? cloneElementWithValidation : cloneElementProd; -const createFactory: any = __DEV__ - ? createFactoryWithValidation - : createFactoryProd; const Children = { map, @@ -126,8 +121,6 @@ export { isValidElement, ReactVersion as version, ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, - // Deprecated behind disableCreateFactory - createFactory, // Concurrent Mode useTransition, startTransition, diff --git a/packages/react/src/ReactElement.js b/packages/react/src/ReactElement.js index e9d721b92693a..af2a6d4fd8a25 100644 --- a/packages/react/src/ReactElement.js +++ b/packages/react/src/ReactElement.js @@ -450,21 +450,6 @@ export function createElement(type, config, children) { ); } -/** - * Return a function that produces ReactElements of a given type. - * See https://reactjs.org/docs/react-api.html#createfactory - */ -export function createFactory(type) { - const factory = createElement.bind(null, type); - // Expose the type on the factory and the prototype so that it can be - // easily accessed on elements. E.g. `.type === Foo`. - // This should not be named `constructor` since this may not be the function - // that created the element, and it may not even be a constructor. - // Legacy hook: remove it - factory.type = type; - return factory; -} - export function cloneAndReplaceKey(oldElement, newKey) { const newElement = ReactElement( oldElement.type, diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index 8281057750e9c..ddca597b2bbc1 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -508,39 +508,6 @@ export function createElementWithValidation(type, props, children) { return element; } -let didWarnAboutDeprecatedCreateFactory = false; - -export function createFactoryWithValidation(type) { - const validatedFactory = createElementWithValidation.bind(null, type); - validatedFactory.type = type; - if (__DEV__) { - if (!didWarnAboutDeprecatedCreateFactory) { - didWarnAboutDeprecatedCreateFactory = true; - console.warn( - 'React.createFactory() is deprecated and will be removed in ' + - 'a future major release. Consider using JSX ' + - 'or use React.createElement() directly instead.', - ); - } - // Legacy hook: remove it - Object.defineProperty(validatedFactory, 'type', { - enumerable: false, - get: function () { - console.warn( - 'Factory.type is deprecated. Access the class directly ' + - 'before passing it to createFactory.', - ); - Object.defineProperty(this, 'type', { - value: type, - }); - return type; - }, - }); - } - - return validatedFactory; -} - export function cloneElementWithValidation(element, props, children) { const newElement = cloneElement.apply(this, arguments); for (let i = 2; i < arguments.length; i++) { diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index c447f554a71ac..5b90aab54ae5a 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -438,34 +438,6 @@ describe('ReactElementValidator', () => { ); }); - if (!__EXPERIMENTAL__) { - it('should warn when accessing .type on an element factory', () => { - function TestComponent() { - return
; - } - - let TestFactory; - - expect(() => { - TestFactory = React.createFactory(TestComponent); - }).toWarnDev( - 'Warning: React.createFactory() is deprecated and will be removed in a ' + - 'future major release. Consider using JSX or use React.createElement() ' + - 'directly instead.', - {withoutStack: true}, - ); - - expect(() => TestFactory.type).toWarnDev( - 'Warning: Factory.type is deprecated. Access the class directly before ' + - 'passing it to createFactory.', - {withoutStack: true}, - ); - - // Warn once, not again - expect(TestFactory.type).toBe(TestComponent); - }); - } - it('does not warn when using DOM node as children', () => { class DOMContainer extends React.Component { render() {