Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The returned types of a component should be re-thinked. #3

Open
thejimmylin opened this issue May 9, 2022 · 2 comments
Open

The returned types of a component should be re-thinked. #3

thejimmylin opened this issue May 9, 2022 · 2 comments

Comments

@thejimmylin
Copy link
Owner

For now the component and JSX related type aliases are like:

/**
 * Component type aliases.
 */
type Component = (props: JsxProps) => Renderable;
type Renderable = JsxNode | NestedArray<JsxNode>;

/**
 * JSX type aliases.
 */
type JsxNode = JsxElement | string;
type JsxElement = { tag: string | Component; props: JsxProps };
type JsxAttrs = { [key: string | symbol]: any };
type JsxProps = JsxAttrs & { children: Array<JsxNode> };

The problem is that the returned type of a component is complicated, which makes the later process of JSX/Fiber/DOM elements complicated, too. If the types of a component could be simpler, it may help a lot.

Also, the fragment should be considered, too.

@thejimmylin
Copy link
Owner Author

thejimmylin commented May 10, 2022

The problems

The returned type of a component could be JsxNode | NestedArray<JsxNode> for now. This is difficult to understand for both of the users and developers of this library. If it can be just JsxNode | Array<JsxNode> or even JsxNode, it will be great.

Why it needs to be like this for now?

Why NestedArray<JsxNode> need to be in the returned type of a component?

  • Because the "react way" to do a v-for is like this:
    <ul>{posts.map(post => <li>{post.title}</li>)}</ul>
    Then it get converted to createJsxElement("ul", null, posts.map(post => <li>{post.title}</li>)).

Reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@thejimmylin and others