N
Directly JSX is quite simply replaced by: The prototype of the function createElement has the following type:We don't have a function. renderand the object created by JSX factory is the result of its challengecreateElement(type: string, props: any, child: Element[]): Element
For example, I wrote my own JSX Factory implementation.class JSX {
static _indent = 0;
static createElement(type = '', props = null, ...child) {
return {
type,
props,
child
};
}
static render({type, props, child}) {
const print = (type, props) => {
const indent = [...new Array(JSX._indent)].map((c) => ' ').join('');
console.log(indent, type, JSON.stringify(props));
}
print(type, props);
JSX._indent += 2;
child.flat(Infinity).forEach((child) => JSX.render(child));
JSX._indent -= 2;
}
}
JSX.render(JSX.createElement('body', null,
JSX.createElement('p', {text: 'Hello'}),
JSX.createElement('p', {text: 'World'}),
JSX.createElement('div', null,
[...new Array(3)].map((, index) => JSX.createElement('p', {text: index}))
),
JSX.createElement('div', null,
[...new Array(3)].map((, i) => {
return [...new Array(3)].map((_, j) => JSX.createElement('tag', {i, j}))
})
),
))
As a result of its work, it is possible to look clearly at the conversion of invested persons. map using React... ♪ When you deal with JSX, you can read about the application of virtual changes to real wood. https://ru.stackoverflow.com/questions/1028948/%D0%9F%D0%BE%D1%87%D0%B5%D0%BC%D1%83-key-%D0%B2-react-%D0%BD%D1%83%D0%B6%D0%B5%D0%BD-%D1%82%D0%BE%D0%BB%D1%8C%D0%BA%D0%BE-%D0%B2-%D0%BF%D0%B5%D1%80%D0%B5%D1%87%D0%B8%D1%81%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F%D1%85 ♪ ♪ ♪