惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

ByteofDev

Making Postgres 42,000x slower because I am unemployed A Quick(ish) Introduction to Tuning Postgres JavaScript numbers have an (adoption) problem My 2025 JavaScript Wishlist JavaScript Benchmarking Is a Mess Replacing Disqus Commenting A deep dive into distributed database architectures 10 ways to speed up web image loading Tailwind has a scalability problem. How can we solve that? Lerna vs Turborepo vs Rush: Which is better in 2023? The 6 JavaScript Projects to watch in 2023 How to use ESM on the web and in Node.js React vs Svelte: Which is better in 2023? 10 ways to speed up JavaScript loading What is Bun, and does it live up to the hype? State of JS 2021 Results and Analysis State of the Web: React 10 ways to speed up web font loading State of the Web: Atomic CSS State of the Web: Static Site Generators State of the Web: Bundlers & Build Tools Migrating ByteofDev from SvelteKit to Astro State of the Web: Serverless Functions State of the Web: Deno Array.map() versus Array.forEach() A quick introduction to JavaScript Maps How I Built the Fastest JavaScript Data Differ State of the Web: WebAssembly When you should and shouldn't use React
Top 5 Alternatives to React in 2023
Jacob Jackson · 2022-09-18 · via ByteofDev

Currently, React is extremely popular, and for good reasons. It is simple and concise. However, looking at some alternatives is a good idea too (check out this article on when to use React). In this article, we will check out various alternatives to React that range from a performance-optimized version to something with an entirely different API.

Top Alternatives To React

Solid.js

Solid.js is an up-and-coming framework that is significantly faster than React. In fact, Solid is one of the fastest frameworks available. Additionally, it provides an API that is very similar to React. Solid uses the same JSX as React does, and it has very similar hooks. However, there are some differences. For example, to optimize your code, Solid requires that when you try to get the value of state, you have to call the state as a function rather than just taking the value directly.

Code Example

import { render } from "solid-js/web";
import { createSignal } from "solid-js";

function Counter() {
	const [count, setCount] = createSignal(0);
	const increment = () => setCount(count() + 1);

	return (
		<>
			<h1>{count()}</h1>
			<button type="button" onClick={increment}>
				Increment
			</button>
		</>
	);
}

render(() => <Counter />, document.body);

Preact

Preact is one of the best alternatives to React, as it is significantly faster, smaller (10kB minified), and offers React compatibility. Unlike most other libraries, Preact offers perfect React compatibility using preact/compat, which means that you can often transform a React app into a Preact app with minimal changes to your code. The simplest way to migrate from React to Preact is to alias React to preact/compat using a bundler or other build tool. What aliasing does is it redirects requests for React to preact/compat, meaning you can keep all of your React imports.

Code Example

/** @jsx h */
/** @jsxFrag Fragment */
import { h, Fragment, render } from "preact";
import { useState } from "preact/hooks";

const rootElement = document.getElementById("root");

export default function Counter() {
	const [count, setCount] = useState(0);
	const increment = () => setCount(count + 1);
	return (
		<>
			<h1>{count}</h1>
			<button onClick={increment}>Increment</button>
		</>
	);
}
render(<Counter />, document.body);

Svelte

Svelte is another well-known alternative that is popular due to not just its performance but also its concise syntax. Unlike the first three alternatives, Svelte has an entirely different syntax that will take some time to learn but is very enjoyable once you get the hang of it. Svelte achieves its performance and brevity using an advanced compiler that turns your Svelte code into native JavaScript. Svelte’s compiler enables you to ship tiny JavaScript bundles, as you don’t have to send any large libraries to the client.

Svelte code differs from React code in many important ways. First of all, Svelte components are Single File Components, which you might be familiar with if you have ever used Vue. Unlike React, where components are just functions or classes in a JavaScript/JSX file, Svelte components are more like HTML files in that there is no JavaScript shell around the markup. Instead, you must put JavaScript inside custom <script> tags. Another major difference is that you manage state using plain JavaScript syntax, rather than useState() and setX(). You can create a variable and use it within the markup, and the markup will automatically update. Finally, Svelte has its own syntax for control flow inside markup, relying on syntax like {#if condition}{/if} instead of nested functions.

If you want to learn more about Svelte as an alternative to React, check out React VS Svelte

Code Example

<script>
	let count = 0;

	function handleClick() {
		count++;
	}
</script>
<h1>{count}</h1>
<button on:click="{handleClick}">Increment</button>

Hyperapp

Hyperapp is a very minimal and fast library for building reactive interfaces. Unlike the rest of the options on this list, Hyperapp makes you write your markup using HyperScript, which utilizes raw functions rather than something like HTML. HyperScript is like using raw React.createElement(), and comes with the advantage of not requiring a compiler. Hyperapp also has a minimal API for state and lifecycle events. All of this minimalism allows Hyperapp to be extremely small, at 4kB minified.

Code Example

import { h, text, app } from "hyperapp";

const increment = (state) => ({
	...state,
	count: state.count + 1,
});

app({
	init: { count: 0 },
	view: ({ count }) =>
		h("main", {}, [
			h("h1", {}, text(count)),
			h("button", { onclick: increment }, text("Increment")),
		]),
	node: document.body,
});

Mithril

Mithril is the final option on our list, and it is also a very good one, as it manages to strike a balance between React’s abstraction and Hyperapp’s minimalism. First, it supports both JSX and raw function calls. The primary way of constructing markup using Mithril is with raw functions, but it is compatible with Babel’s JSX compiler, so you cna do either. Second, Mithril has a more minimal automatic update system. The markup will only update after event handlers, HTTP requests using m.request(), and route changes. Otherwise, you can manually call m.redraw() to have Mithril update the markup. Otherwise, Mithril is a lot like Hyperapp with more features.

Code Example

import m from "https://esm.run/mithril";
function counter() {
	let count = 0;
	function increment() {
		count++;
	}
	return {
		view: () => [
			m("h1", count),
			m("button", { onclick: increment }, "Increment"),
		],
	};
}
m.mount(document.body, counter);

Conclusion

That’s it! I hope you found a least one library here that you will try out. React is great for a lot of things, but not for everything. Personally, my favorites on this list are Svelte and Solid. Also, if you liked reading this, join the mailing list or subscribe to RSS below! Thanks for reading!