Я строю приложение ERP с React nodejs и MSSQL. Для React и Node я использую рабочие пространства для обмена объектом JavaScript между передним и бэкэнд для 3 вещей: < /p>
Проверка фронтальной формы < /li>
Проверка формы на стороне сервера < /li>
Создание Database in Secuelize. Я думаю о том, чтобы динамически генерировать поля формы реагирования из объекта во время строительства вместо времени выполнения.
Причина - иметь единый источник истины, одно обновление обновляет все. Приложение ERP будет иметь сотни полей ввода без сложных операций или действий (CRUD). Я думал создать файлы JSX, как показано ниже во время Prebuild: < /p>
// UserSchema.json
const user = [
{ label: "Name", type: "text" },
{ label: "Email", type: "email" },
{ label: "Age", type: "number" }
];
< /code>
// CodeGenerator.js
// Of course this is a hardcoded example but it will be dynamically generate for all *Schema.json files.
const fs = require("fs");
const jsx = `
import React from "react";
export default function GeneratedFormItems() {
return (
${formItems.map(item => `
${item.label}
`).join("")}
);
}
`;
fs.writeFileSync("src/GeneratedFormItems.js", jsx);
< /code>
\\ package.json
"prebuild": "node CodeGenerator.js",
< /code>
My Question is:
Is this worth it or feasible.
What are the potential shortfall or challenges I may face with this approach.
Has anyone ever tried something like this?
Are there any libraries to help with this?
Did some research but could not find much on it. I know one thing I may encounter is hot reloading may be slower and it will not prebuild on hot reload.
Я строю приложение ERP с React nodejs и MSSQL. Для React и Node я использую рабочие пространства для обмена объектом JavaScript между передним и бэкэнд для 3 вещей: < /p> [list] [*] Проверка фронтальной формы < /li> Проверка формы на стороне сервера < /li> Создание Database in Secuelize. Я думаю о том, чтобы динамически генерировать поля формы реагирования из объекта во время строительства вместо времени выполнения. Причина - иметь единый источник истины, одно обновление обновляет все. Приложение ERP будет иметь сотни полей ввода без сложных операций или действий (CRUD). Я думал создать файлы JSX, как показано ниже во время Prebuild: < /p> // UserSchema.json const user = [ { label: "Name", type: "text" }, { label: "Email", type: "email" }, { label: "Age", type: "number" } ]; < /code> // CodeGenerator.js // Of course this is a hardcoded example but it will be dynamically generate for all *Schema.json files.
const fs = require("fs");
const jsx = ` import React from "react";
export default function GeneratedFormItems() { return (
${formItems.map(item => ` ${item.label}
`).join("")}
); } `;
fs.writeFileSync("src/GeneratedFormItems.js", jsx); < /code> \\ package.json "prebuild": "node CodeGenerator.js", < /code> My Question is:
Is this worth it or feasible. [*]What are the potential shortfall or challenges I may face with this approach. [*]Has anyone ever tried something like this? [*]Are there any libraries to help with this? [/list] Did some research but could not find much on it. I know one thing I may encounter is hot reloading may be slower and it will not prebuild on hot reload.