Skip to content

Commit

Permalink
Remove React.createFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Dec 6, 2023
1 parent aba93ac commit baa14c7
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 96 deletions.
1 change: 0 additions & 1 deletion packages/react-is/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions packages/react/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -63,7 +62,6 @@ import {
} from './ReactHooks';
import {
createElementWithValidation,
createFactoryWithValidation,
cloneElementWithValidation,
} from './ReactElementValidator';
import {createServerContext} from './ReactServerContext';
Expand All @@ -78,9 +76,6 @@ const createElement: any = __DEV__
const cloneElement: any = __DEV__
? cloneElementWithValidation
: cloneElementProd;
const createFactory: any = __DEV__
? createFactoryWithValidation
: createFactoryProd;

const Children = {
map,
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 0 additions & 15 deletions packages/react/src/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. `<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;
return factory;
}

export function cloneAndReplaceKey(oldElement, newKey) {
const newElement = ReactElement(
oldElement.type,
Expand Down
33 changes: 0 additions & 33 deletions packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,34 +438,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', () => {
class DOMContainer extends React.Component {
render() {
Expand Down

0 comments on commit baa14c7

Please sign in to comment.