Hyperapp is an ultra lightweight (1kb), minimal, functional, JavaScript library for building UIs. It comes with a VDOM engine and state management without any dependencies.
Duration
2 min
Access
Free
Transcript
Available
Hyperapp is an ultra lightweight (1kb), minimal, functional, JavaScript library for building UIs. It comes with a VDOM engine and state management without any dependencies.
In this lesson, we learn how to use JSX with Hyperapp. By installing a Babel plugin, we can instruct it to transpile JSX to Hyperapp's h method for a better developer experience.
Video Transcript
Instructor: Hyperapp uses H-functions in order to create virtual DOM nodes. For example, if we wanted to make a div and an H1, this is how we would do it.
If we save this, our DOM renders the div and an H1. However, this can be quite cumbersome and tedious to use, if you're making more complex components in this. Luckily, we can add jsx to a hyperapp pretty easily.
The first thing I want to do is, go to your terminal and type in either npm install, or you want to add babel-plugin-transform-react-jsx and save it to your dev dependencies.
What this will do is it would allow us to transform our jsx into our H-calls. The second step is, we'll need to instruct babel to transpile our core correctly, and we do this by initiating the plugin.
We'll write a plugin's. We'll have an array, and this will actually need to be in array as well, because of it will have multiple arguments. The first one is transform-react-jsx, and the second one is an object. We'll set a key of pragma to H.
This is what tells a babel to use our H-functions where it finds jsx. Then, we can go back to our component and we can replace it with much more familiar mark up from jsx. We save it and we refresh the page. We should see a div and an H1.