mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Remove React.createFactory (#27798)
`React.createFactory` has been long deprecated. This removes it for the next release.
This commit is contained in:
parent
13f35433bc
commit
2aed507a76
|
|
@ -40,7 +40,6 @@ ReactIs.isValidElementType(FunctionComponent); // true
|
||||||
ReactIs.isValidElementType(ForwardRefComponent); // true
|
ReactIs.isValidElementType(ForwardRefComponent); // true
|
||||||
ReactIs.isValidElementType(Context.Provider); // true
|
ReactIs.isValidElementType(Context.Provider); // true
|
||||||
ReactIs.isValidElementType(Context.Consumer); // true
|
ReactIs.isValidElementType(Context.Consumer); // true
|
||||||
ReactIs.isValidElementType(React.createFactory("div")); // true
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Determining an Element's Type
|
### Determining an Element's Type
|
||||||
|
|
|
||||||
12
packages/react-is/src/__tests__/ReactIs-test.js
vendored
12
packages/react-is/src/__tests__/ReactIs-test.js
vendored
|
|
@ -67,18 +67,6 @@ describe('ReactIs', () => {
|
||||||
expect(ReactIs.isValidElementType(MemoComponent)).toEqual(true);
|
expect(ReactIs.isValidElementType(MemoComponent)).toEqual(true);
|
||||||
expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true);
|
expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true);
|
||||||
expect(ReactIs.isValidElementType(Context.Consumer)).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.Fragment)).toEqual(true);
|
||||||
expect(ReactIs.isValidElementType(React.StrictMode)).toEqual(true);
|
expect(ReactIs.isValidElementType(React.StrictMode)).toEqual(true);
|
||||||
expect(ReactIs.isValidElementType(React.Suspense)).toEqual(true);
|
expect(ReactIs.isValidElementType(React.Suspense)).toEqual(true);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ export {
|
||||||
cloneElement,
|
cloneElement,
|
||||||
createContext,
|
createContext,
|
||||||
createElement,
|
createElement,
|
||||||
createFactory,
|
|
||||||
createRef,
|
createRef,
|
||||||
use,
|
use,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ export {
|
||||||
cloneElement,
|
cloneElement,
|
||||||
createContext,
|
createContext,
|
||||||
createElement,
|
createElement,
|
||||||
createFactory,
|
|
||||||
createRef,
|
createRef,
|
||||||
use,
|
use,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ export {
|
||||||
cloneElement,
|
cloneElement,
|
||||||
createContext,
|
createContext,
|
||||||
createElement,
|
createElement,
|
||||||
createFactory,
|
|
||||||
createRef,
|
createRef,
|
||||||
use,
|
use,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ export {
|
||||||
cloneElement,
|
cloneElement,
|
||||||
createContext,
|
createContext,
|
||||||
createElement,
|
createElement,
|
||||||
createFactory,
|
|
||||||
createRef,
|
createRef,
|
||||||
use,
|
use,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import {createRef} from './ReactCreateRef';
|
||||||
import {forEach, map, count, toArray, only} from './ReactChildren';
|
import {forEach, map, count, toArray, only} from './ReactChildren';
|
||||||
import {
|
import {
|
||||||
createElement,
|
createElement,
|
||||||
createFactory,
|
|
||||||
cloneElement,
|
cloneElement,
|
||||||
isValidElement,
|
isValidElement,
|
||||||
} from './jsx/ReactJSXElement';
|
} from './jsx/ReactJSXElement';
|
||||||
|
|
@ -62,7 +61,6 @@ import {
|
||||||
useOptimistic,
|
useOptimistic,
|
||||||
useActionState,
|
useActionState,
|
||||||
} from './ReactHooks';
|
} from './ReactHooks';
|
||||||
|
|
||||||
import ReactSharedInternals from './ReactSharedInternalsClient';
|
import ReactSharedInternals from './ReactSharedInternalsClient';
|
||||||
import {startTransition} from './ReactStartTransition';
|
import {startTransition} from './ReactStartTransition';
|
||||||
import {act} from './ReactAct';
|
import {act} from './ReactAct';
|
||||||
|
|
@ -111,8 +109,6 @@ export {
|
||||||
isValidElement,
|
isValidElement,
|
||||||
ReactVersion as version,
|
ReactVersion as version,
|
||||||
ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
||||||
// Deprecated behind disableCreateFactory
|
|
||||||
createFactory,
|
|
||||||
// Concurrent Mode
|
// Concurrent Mode
|
||||||
useTransition,
|
useTransition,
|
||||||
startTransition,
|
startTransition,
|
||||||
|
|
|
||||||
|
|
@ -331,34 +331,6 @@ describe('ReactElementValidator', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!__EXPERIMENTAL__) {
|
|
||||||
it('should warn when accessing .type on an element factory', () => {
|
|
||||||
function TestComponent() {
|
|
||||||
return <div />;
|
|
||||||
}
|
|
||||||
|
|
||||||
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', async () => {
|
it('does not warn when using DOM node as children', async () => {
|
||||||
class DOMContainer extends React.Component {
|
class DOMContainer extends React.Component {
|
||||||
ref;
|
ref;
|
||||||
|
|
|
||||||
|
|
@ -757,49 +757,6 @@ export function createElement(type, config, children) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
let didWarnAboutDeprecatedCreateFactory = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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. `<Foo />.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;
|
|
||||||
|
|
||||||
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(factory, '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 factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function cloneAndReplaceKey(oldElement, newKey) {
|
export function cloneAndReplaceKey(oldElement, newKey) {
|
||||||
return ReactElement(
|
return ReactElement(
|
||||||
oldElement.type,
|
oldElement.type,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user