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

feat: allow null, undefined, booleans, string and numbers as jsx elements #221

Merged
merged 2 commits into from
Oct 17, 2023

Conversation

ncpa0cpl
Copy link
Collaborator

@ncpa0cpl ncpa0cpl commented Oct 17, 2023

It is now possible to return other things from function components than elements created via createElement or JSX syntax. Anything that is not an object, string or number will be treated as if <></> was returned, returned strings and numbers will be treated as <>{value}</>, objects are expected to be elements created via createElement or JSX syntax (no change here).

This means that the following components are now possible:

function MyComponent() {
  return !!condition && <div>...</div>;
} 

function MyComponent() {
  return "Hello";
} 

function MyComponent() {
  return 2023;
} 

// ok
renderToHtml(
  <div>
    <MyComponent />
  </div>
)

@ncpa0cpl ncpa0cpl merged commit f7a3e87 into master Oct 17, 2023
3 checks passed
@ncpa0cpl ncpa0cpl deleted the feat/allow-nulish-types-as-jsx-elements branch October 17, 2023 10:39
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

Successfully merging this pull request may close these issues.

1 participant