React vs Elm: Creating a comment box component in Elm

I recently published an article on CodeMentor.io titled “Building a Facebook-like comment box: a React tutorial in Elm” where I use the Elm programming language to essentially duplicate the React.js tutorial.

Update: I conducted a webinar where we built an Instagram clone in Elm.

The article has code examples and a step-by-step on installing Elm, running the Elm Reactor and then writing the code for the comment box. There is no JavaScript involved aside from the JavaScript generated by the Elm compiler.

elm vs react tutorial on codementor by Rudolf Olah
Click above to read the Elm Tutorial on building a comment box just like Facebook’s

Comparing Elm to React for JavaScript Frontend Web Development

The article has a brief comparison between React and Elm. It explains why you would want to use Elm for building your JavaScript frontend:

While the performance of React is awesome, at a certain point, you will notice that having React just isn’t enough.

You’ll also want Redux, Flux, or some other data flow library installed.

You will want Webpack and Babel installed so that you can use the latest features of ES6 (also known as EMCAScript 2016).

Then you’ll probably want to add type-checking and static types at that point, so you will also need to install Flow, a JavaScript type-checker.

Elm will give all the goodies that React, Redux/Flux, and Flow give you but as a collective programming language rather than as individual libraries.

Essentially, Elm is a functional language with the framework built in for solid frontend web development, it compiles to JavaScript. It’s similar to TypeScript in that respect, however Elm goes much further because it has its own syntax for better type-checking and compilation.

Also, instead of having to find individual tools, everything that you need to create fast components and single page applications come with Elm. It’s a batteries-included language. It comes with a REPL (command line interface). The Elm-Reactor included with it will reload any changes you have made to an Elm file. With all these elements, it is the perfect language for rapid frontend web development. You can learn Elm quickly, and learn to quickly build, test, and refactor Elm components in a way that can’t be replicated by tools like TypeScript or ES6 or React or Angular.

Compare React and Angular To Elm

So while React is great for creating web components, when we compare it to Elm, it can be hard to get started because it requires a bit more infrastructure around it (with Babel, Webpack, Flow, TypeScript, etc.) to really get started on developing a production-ready web application.

Note: React isn’t the only JavaScript framework/language/library to suffer from this, Angular also has a problem with setting up infrastructure (as do other JavaScript libraries). This is probably why React killing Angular in the JavaScript web framework wars is not so far-fetched. You can learn React and Angular fairly easily for the simple tasks. However, when projects become complex, the infrastructure starts to get in the way and it can be hard to learn how to debug the issues. It may be possible that if you compare other JavaScript frameworks like Vue.js to Elm, you will find they have better infrastructure and a good developer feedback loop.

Updated: Instagram Clone Article Published

It’s one of the first pieces of code I’ve written in Elm. I have been working on two other projects; one is an Instagram-clone, which I did an “office hours” live coding session for on CodeMentor.io.

The instagram code is neat because you can see how quickly you can write up a grid layout. You can see how to work with modals/pop-ups and how to manage state within an app. You can check out the code for the instagram clone here. The instagram clone is licensed under the Apache license 2.0.

Event Creation Tool written in Elm

The event creation tool for an event ticket sales page is cool. It explores more state management in the context of an app. For example there’s a way to switch the type of event you’re creating in the app. When you switch, an explanation page appears in between to give you guidance on how to create the different type of event that you just switched to. the event creator web app is licensed under the AGPL. You can check out the code for the event creation page for an event ticket sales website is here.

More Articles On Elm

I will be publishing another article on Elm (update: it has been published) very soon that is a continuation of the Instagram-clone code. It will include an API server to show how to use HTTP and AJAX calls. Furthermore, it will show you how to embed and fullscreen a component. This is vital if you want to use Elm today in an existing project and integrate components in a piecemeal fashion.

2017 UPDATE

instagram clone in elmUPDATE: The 2-part article on creating an Instagram clone in Elm (instaelm) has been posted on Codementor: