Million: The Virtual DOM Replacement for React

2023/06/22
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

Million is a virtual DOM replacement for React that aims to provide better performance and developer experience. It was created by Aiden Bai and is licensed under the MIT license.

According to the author, Million is up to 10 times faster than React in some cases. It achieves this by optimizing the diffing algorithm and reducing the amount of work done during updates. Additionally, Million provides a simpler API and better TypeScript support.

To use Million, developers can simply replace their React import with a Million import and start using the new API. Million also provides a compatibility layer for React components, allowing developers to gradually migrate their codebase.

Here's an example of how to create a Million component:

import { h, mount } from 'million';

function MyComponent(props) {
  return h('div', { class: 'my-component' }, [
    h('h1', {}, props.title),
    h('p', {}, props.text),
  ]);
}

mount(MyComponent({ title: 'Hello', text: 'World' }), document.body);

In this example, Million's h function is used to create a virtual DOM tree, which is then mounted to the actual DOM using the mount function.

Overall, Million is an interesting alternative to React that promises better performance and developer experience. While it's still a relatively new project, it's worth keeping an eye on for developers looking to optimize their web applications.