Memorize the JSX element.
In
import { createElement } from 'react';
export default function Foo(props) {
const { message } = props;
return (
<div>
Demo:
<p x-memo>hello {message}</p>
</div>
);
}
Out
import { createJSXMemo as __create_jsx_memo__ } from "babel-plugin-transform-jsx-memo/lib/runtime";
import { createElement } from 'react';
export default function Foo(props) {
const {
message
} = props;
return <div>
Demo:
{__create_jsx_memo__(() => <p>hello {message}</p>, 0)}
</div>;
}
$ npm install babel-plugin-transform-jsx-memo
.babelrc
{
"plugins": ["transform-jsx-memo"]
}
$ babel --plugins transform-jsx-memo script.js
require("babel-core").transform("code", {
plugins: ["transform-jsx-memo"]
});