This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Render Text with JSX in Hyperapp

    Kyle ShevlinKyle Shevlin

    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.

    javascriptJavaScript
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss