jsx-xml
jsx-xml copied to clipboard
Support for async components, support for context
Resolves #21
- Added a function
renderAsyncwhich supports rendering async components, sequentially - Added support for
useContextas a way to pass down props easily, it works with async components too - To support concurrency in jsx
getCurrentElementI have had to create a closure for the builtin components, which now can be instantiated with their owngetCurrentElementwhich can accept a scoped stack - I also had to update the
@types/reactpackage to have support for async components in jsx, also notice that since react 19 you have to declare jsx components under the React namespace:
declare global {
namespace React {
namespace JSX {
interface IntrinsicElements {
// ....
Example:
const context = createContext('default')
const AsyncComponent = async (props: { x: number }) => {
const value = useContext(context)
// Simulate async operation
await new Promise((resolve) => setTimeout(resolve, 0));
return (
<item x={props.x}>
<test />
{value}
</item>
);
};
let xml = (
await renderAsync(
<root>
<context.Provider value={'value'}>
<AsyncComponent x={5} />
</context.Provider>
</root>,
)
).end({ headless: true });