Support for JSX
See original GitHub issueIn the README it mentions that this ever-differently named project supports JSX. In fact it does not.
Here’s an example using the default h
function:
function Title(message) {
return h(
'h1',
{},
`Hello, ${message}!`
)
}
let title = null
title = render(title, Title('Joe'), document.body)
This works as expected. Now if we change this to use JSX:
function Title({message}) {
return (
<nav>
<h1>Hello, {message}!</h1>
</nav>
)
}
let title = null
title = render(title, <Title message='Joe' />, document.body)
This does not work. Instead we get an error:
InvalidCharacterError: The string contains invalid characters.
This points to line 48.
That because of changes made to the h
function. This is because, unlike the h
function, a JSX tag returns a function. In Hyperapp, you check for a name of value “function”. In this lib you do not. Currently the h
function just returns a vnode
:
return {
name: name,
attributes: attributes || {},
children: children,
key: attributes && attributes.key
}
You could change it to this to restore support for JSX tags:
if (typeof name === 'function') {
return name(attributes || {}, children)
} else {
return {
name: name,
attributes: attributes || {},
children: children,
key: attributes && attributes.key
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Documentation - JSX - TypeScript
TypeScript supports embedding, type checking, and compiling JSX directly to JavaScript. Basic usage. In order to use JSX you must do two things....
Read more >Introducing JSX - React
It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI...
Read more >Support for the experimental syntax 'jsx' isn't currently enabled ...
Support for the experimental syntax 'jsx' isn't currently enabled after creating a TypeScript react project and installing an NPM package with ...
Read more >JSX - Meta Open Source
JSX is an XML-like syntax extension to ECMAScript without any defined semantics. It's NOT intended to be implemented by engines or browsers.
Read more >React JSX - W3Schools
React supports if statements, but not inside JSX. To be able to use conditional statements in JSX, you should put the if statements...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Some pros and cons were here: https://github.com/hyperapp/hyperapp/issues/569
0b9667a38fff30f9f68694bdbaea8ac2af477d62