escript
is compatible with any node modules included ReactJS.
npm init
npm i @chientrm/es react react-dom
npm i html-webpack-plugin webpack-cli webpack-dev-server --save-dev
import React from "react";
import ReactDOM from "react-dom";
import { eEval } from "@chientrm/es";
import app from "./App.e";
const App = eEval(
[{ createElement: React.createElement, useState: React.useState }],
"App.e",
app
);
const root = document.createElement("div");
document.body.appendChild(root);
ReactDOM.render(React.createElement(App), root);
Label = props =>
createElement("span", null, "You clicked " + props.value + " times!")
App = _ => (
countState = useState(0)
count = countState[0]
setCount = countState[1]
buttonClick = _ => setCount(count + 1)
result = createElement("div", null,
createElement(Label, {value = count}, null)
createElement("button", {onClick = buttonClick}, "Click!")
)
)
const path = require("path");
const HtmlPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./index.js",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "index_bundle.js",
},
mode: "development",
devtool: "eval",
module: {
rules: [
{
test: /\.e/,
exclude: /node_modules/,
type: "asset/source",
},
],
},
plugins: [new HtmlPlugin()],
};
npx webpack serve
escript
is fully compatible with React Hook but not React class component becauseescript
does not support the class declaration.- The syntax is quite inconvenient for now compared to JSX.
To practically implement ReactJS with escript
, there must be a jsx
equivalent in the future.