Render Text with JSX in Hyperapp

Kyle Shevlin
InstructorKyle Shevlin
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

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.

Instructor: [00:00] 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.

[00:09] 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.

[00:27] 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.

[00:40] 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.

[00:54] 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.

[01:14] 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.

egghead
egghead
~ 9 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today