Reference

createFactory(type)

Call createFactory(type) to create a factory function which produces React elements of a given type.

Then you can use it to create React elements without JSX:

Parameters

  • type: The type argument must be a valid React component type. For example, it could be a tag name string (such as 'div' or 'span'), or a React component (a function, a class, or a special component like ).

Returns

Returns a factory function. That factory function receives a props object as the first argument, followed by a list of ...children arguments, and returns a React element with the given type, props and children.


Usage

Creating React elements with a factory

Although most React projects use to describe the user interface, JSX is not required. In the past, createFactory used to be one of the ways you could describe the user interface without JSX.

Call createFactory to create a factory function for a specific element type like 'button':

Calling that factory function will produce React elements with the props and children you have provided:

This is how createFactory was used as an alternative to JSX. However, createFactory is deprecated, and you should not call createFactory in any new code. See how to migrate away from createFactory below.


Alternatives

Copying createFactory into your project

If your project has many createFactory calls, copy this createFactory.js implementation into your project:

This lets you keep all of your code unchanged except the imports.


Replacing createFactory with createElement

If you have a few createFactory calls that you don’t mind porting manually, and you don’t want to use JSX, you can replace every call a factory function with a call. For example, you can replace this code:

with this code:

Here is a complete example of using React without JSX:


Replacing createFactory with JSX

Finally, you can use JSX instead of createFactory. This is the most common way to use React: