Skip to content

Instantly share code, notes, and snippets.

@eps1lon
Created March 22, 2021 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eps1lon/61f12fc47facba60b7572b38b6084285 to your computer and use it in GitHub Desktop.
Save eps1lon/61f12fc47facba60b7572b38b6084285 to your computer and use it in GitHub Desktop.
new JSX transform

Summary explainer: facebook/react#20031 (comment)

playground:

Input:

<ComponentA />;
<ComponentD prop="A" key="K" />;
<ComponentB {...props} />;
<ComponentC {...props} key="K" />;
<ComponentE key="K" {...props} />;

Output:

import { createElement as _createElement } from "react";
import { jsx as _jsx } from "react/jsx-runtime";

/*#__PURE__*/
_jsx(ComponentA, {});

/*#__PURE__*/
_jsx(ComponentD, {
  prop: "A"
}, "K");

/*#__PURE__*/
_jsx(ComponentB, { ...props
});

/*#__PURE__*/
_createElement(ComponentC, { ...props,
  key: "K"
});

/*#__PURE__*/
_jsx(ComponentE, { ...props
}, "K");

ESLint warn against spread after key: https://astexplorer.net/#/gist/b8acc14dece98274719a0dca27fe489f/398cfa3dac05edc8479feb747d74f5bceb73e6be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment