acdlite / recompose

A React utility belt for function components and higher-order components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove usage of `createFactory`

amannn opened this issue · comments

In react@16.13.1 this library triggers a warning:

Warning: React.createFactory() is deprecated and will be removed in a future major release. Consider using JSX or use React.createElement() directly instead.

It looks like this repository uses this API in quite a few places, so perhaps this should be refactored?

Was looking to see how hard this would be an it does look a bit daunting! createFactory returns a function that creates an element and createElement returns an element. Looks like the library is using createFactory to defer the mapping of props.

I wonder if it would make sense to bring the createFactory logic into this library and have it use createElement, that means the warning would go away, but if createFactory is relying on internals..... (which it isn't)

createFactory

/**
 * 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;
}

Not really sure WHY they are dropping support for createFactory if createElement is going to continue to exist....

Is this fixed?

Since this method (createFactory) has been deprecated in React 16.x, is it possible that this project will stop working when/if a future release of React drops support for it?

Now that our projects have moved to React 17 we are now also seeing this warning from another npm package we use that itself uses recompose. Our assumption is that in React 18 it will become breaking.