This is a concept that is not in react...It makes much sencse sence with typescript ... Besides react fragments all JSX.Elements declared render a DOM / blessed element. From bottom to the top. Virtual element let component authors declare element's children props that won't be rendered at all. Useful to define complex component API as markup and then render another thing that implements it. Example: A Tab Panel (types definitions as JSX ELement Props) ## Componnet decarations (extend VirtualComponent then they wont be rendered (wont create any elememt only provide parent with data.)) ```jsx class TabHeadings extends VirtualComponent{ } class TabBlocks extends VirtualComponent{ } class TabBlock extends VirtualComponent{ } class TabHeading extends VirtualComponent{ } ``` ## Props declarations: Component Props, . where the semantics The API semantics & structure is really defined here (the markup the user needs to write) ```tsx interface TabPanelProps { /** Only must contain only TabHeadings and TabBlocks children,and only one of each. */ children: (TabHeadings | TabBlocks)[] } /** only alows TabBlock there must be */ interface TabBlocksProps { children: JSX.BlessedJsxNode | TabBlock[] } interface TabBlockProps { id: string, children: JSX.BlessedJsxNode } interface TabHeadingsProps { children: JSX.BlessedJsxText | TabHeading[] } /** inner htext is mandatoryy and only text. id attr is mandatory. */ interface TabHeadingProps { active?: boolean, focus?: boolean, id: string, children: JSX.BlessedJsxNode } ``` ## Users code It needs to respect Props structure or fail to compile ```tsx const UserApp2 =
Welcome to the soper heroe store, use the tabs below to focus on special super powers. Here we are inside real blessed components, container box for exampe. But below (TabPanel> are virtual components that won't be rendered at all. Probably other elements wil be rendered instead Removint this text gives an error Ttiel1 there could be text or spaces between Headings but not other elements not even intrinsic so uncommenting the next will give error _ {/* */} blocks must have text and can contain any other kind of element There cannot be any element besides text between blocks so uncomenting the follwoiing gives {/* */} id is mandatory > {/* There cannot be text between TabBlocks and TabPanel asd123 123 uncommenting this text vigeserror*/}
``` ## The actual implementation we implemetnt it we hyst a couple of blessing elements ```jsx class TabPanel extends Component{ render() { return
Welcome to the soper heroe store, use the tabs below to focus on special super powers.
} } ``` # TIPS for TypeScript begginrs * Notice that COmponent's accept above Props and returns a much simpler structure (only blessed elements that **will consume the user input, structure, attributes, cgiuldrem etc) as input data / optinos: * union with JSX.BlessedJsxNode will include elemnts * unioin with JSX.BlessedJsxText to include text * Children validation TIP: * {} no children alowed or text * children: JSX.BlessedJsxNode exactly one children , of any type * children [A, B, C] : exacly three childrens and their types must have that order. * children A|B|C|JSX.BlessedJsxText any of a, b, v or text, in any order any amount * children: Type | JSX.BlessedJsxNode will allow children of * Type Union with `JSX.BlessedJsxText``to allow Text (string) children # Bless options in blessed feets very well with transversal convepts like border and scrollbar since it allows to separate that seantics with the elelnet: Currently is all mixed in the same declaration object - and spreaded ... at the same time.. ## Proposal : Children eleemnt affects all descendants of its parent: ```tsx const userCode = <---- .... add a ScrollBar to the list table parent <--- the style is only for the head title1title2> <---- style for cels , spanm etc value1value2
<-- all siblings Button> <---- no more focus other content ``` ## Proposal: React-like Providers (although react's care musch simpler. (Cannot be nested) or doesn't contain qualifiers like these) Wrap elements to affect options of children: ```tsx