Hacker News new | ask | show | jobs
by xrd 2858 days ago
Can someone summarize with an example that shows why this has benefits over React? I read the first few examples and it seems simple enough, but I've bought into the whole JSX benefit and don't see how those first few examples allow me to write less code and code that is closer to the HTML I'll eventually be rendering. Is it the tooling that mithril allows me to forget about? Is it something special that mithril gives me a novice who doesn't realize I'm being held back by using React?
2 comments

(Mithril author here)

Usually, what I hear from folks is that you come out of using Mithril with more transferable knowledge than something like React.

One example that comes to mind was when someone realized you could implement an incredibly simple atomic CSS composition framework by basically doing this:

    /* some atomic CSS */
    .primary-color-700 {color:blue;}
    .pad-700 {padding:1em;}

    /* a bog standard CSS selector string */
    const MyWidget = '.primary-color-700.pad-700';

    /* a Mithril element */
    m(MyWidget) // <MyWidget /> in JSX
So you can get a fairly aggressive CSS optimization scheme for basically free, and you can iteratively improve the quality of your atomic CSS as you learn more about plain CSS / semantic taxonomy practices. And meanwhile, you're still just writing bog standard CSS and Mithril templates. There's no compile-time shenanigans to dedupe styles, no extra library runtime, and CSS is actually CSS so if you server-render you stay on the browser's streaming rendering happy path instead of waiting blocked on scripts.

Now compare with what one would do with most frameworks: one would pick some CSS-in-JS library, get things done and over with, but probably learn nothing interesting in the process and have little idea of what sort of code is actually getting shipped to customers.

This is really useful. Thank you.
I've also bought into JSX. I use JSX in all my Mithril projects.

Advantages over React: Routing built in. Smaller/faster. You don't get numb to the word "dangerously" being used routinely for data that you trust.

Debatable: Mithril does not wrap native browser events. This is an advantage because what you learn about events applies outside the framework. It may also be a disadvantage; debatable.

Disadvantage: React is a more attractive keyword on your resume and in job listings.

EDIT: Forgot my example - https://medium.com/front-end-hacking/how-it-feels-to-learn-j...