Solid.js
Solid
A declarative UI library based on fine-grained reactivity. Provides excellent performance with a React-like syntax through compile-time optimization without a Virtual DOM.
Solid
A declarative UI library based on fine-grained reactivity. Provides excellent performance with a React-like syntax through compile-time optimization without a Virtual DOM.
Solid.js is a reactive JavaScript library for building modern declarative UIs. It provides JSX syntax and a component-based architecture similar to React, yet uses a fundamentally different reactivity model. Components run only once, and afterward only the parts that need it are updated precisely by fine-grained reactivity units called Signals. This enables highly efficient UI updates without unnecessary re-rendering.
Solid.js was started by Ryan Carniato in 2018 and officially released in 2021. Carniato is a member of the MarkoJS core team and currently an engineer at Netlify, and has researched reactivity systems for more than 10 years. His philosophy was to "combine React's developer experience with Knockout.js's performance," and Solid.js is the result of achieving that goal. In benchmarks, Solid.js consistently shows performance close to Vanilla JavaScript and outperforms other frameworks by a wide margin.
Fine-grained Reactivity is the core concept of Solid.js. React's Virtual DOM compares the entire component tree when state changes to find the changes, but Solid.js does not need this process. When a Signal changes, only the DOM nodes that subscribe to that Signal are updated directly. This is possible because the dependency graph is analyzed at compile time, so there is almost no runtime overhead. createSignal, createEffect, and createMemo are the basic building blocks of this reactivity system.
In practice, the strengths of Solid.js are performance and bundle size. The bundle size of Solid.js is about 7KB (gzip), much smaller than React (~40KB). It also consistently ranks at the top of the JS Framework Benchmark, delivering outstanding performance especially in large list rendering and frequent updates. Through a meta-framework called SolidStart, it also supports full-stack features such as SSR, routing, and API endpoints. If you are a React developer, the syntax is familiar, so you can gain the performance benefits with a low learning curve.
import { createSignal } from 'solid-js'; // Signal: Solid.jsμ λ°μν μν // getter ν¨μμ setter ν¨μλ₯Ό λ°ν (Reactμ λ€λ¦!) function Counter() { // countλ ν¨μ! count()λ‘ κ°μ μ½μ const [count, setCount] = createSignal(0); // μ»΄ν¬λνΈ ν¨μλ ν λ²λ§ μ€νλ¨ console.log('μ»΄ν¬λνΈ μμ± - μ΄ λ‘κ·Έλ ν λ²λ§ μΆλ ₯!'); return ( <div> {/* count()λ₯Ό νΈμΆν΄μΌ κ°μ μ½μ μ μμ */} <p>μΉ΄μ΄νΈ: {count()}</p> <button onClick={() => setCount(count() + 1)}> μ¦κ° </button> </div> ); } // Reactμμ μ°¨μ΄μ // React: const [count, setCount] = useState(0); // countλ κ° // Solid: const [count, setCount] = createSignal(0); // countλ ν¨μ
import { createSignal, createEffect, createMemo } from 'solid-js'; function UserProfile() { const [firstName, setFirstName] = createSignal('κΉ'); const [lastName, setLastName] = createSignal('μ² μ'); // createMemo: νμλ κ°μ μΊμ± (Reactμ useMemoμ μ μ¬) // firstNameμ΄λ lastNameμ΄ λ³κ²½λ λλ§ μ¬κ³μ° const fullName = createMemo(() => { console.log('fullName κ³μ° μ€...'); return `${firstName()} ${lastName()}`; }); // createEffect: λΆμ ν¨κ³Ό μ²λ¦¬ (Reactμ useEffectμ μ μ¬) // μμ‘΄μ± λ°°μ΄μ΄ νμ μμ - μλμΌλ‘ μΆμ ! createEffect(() => { // fullName()μ μ¬μ©νλ©΄ μλμΌλ‘ μμ‘΄μ±μ΄ μΆμ λ¨ console.log(`μ΄λ¦μ΄ λ³κ²½λ¨: ${fullName()}`); // μ 리(cleanup) ν¨μ onCleanup(() => console.log('μ 리 μμ μ€ν')); }); return ( <div> <input value={firstName()} onInput={(e) => setFirstName(e.target.value)} /> <input value={lastName()} onInput={(e) => setLastName(e.target.value)} /> <h2>μλ νμΈμ, {fullName()}λ!</h2> </div> ); }
import { createSignal, Show, For } from 'solid-js'; function TodoList() { const [todos, setTodos] = createSignal([ { id: 1, text: 'Solid.js λ°°μ°κΈ°', done: false }, { id: 2, text: 'νλ‘μ νΈμ μ μ©νκΈ°', done: false } ]); const [showCompleted, setShowCompleted] = createSignal(true); const toggleTodo = (id) => { setTodos(todos().map(todo => todo.id === id ? { ...todo, done: !todo.done } : todo )); }; return ( <div> <label> <input type="checkbox" checked={showCompleted()} onChange={() => setShowCompleted(!showCompleted())} /> μλ£λ νλͺ© νμ </label> {/* For: ν¨μ¨μ μΈ λ¦¬μ€νΈ λ λλ§ (map λμ μ¬μ©) */} <For each={todos()}> {(todo) => ( {/* Show: μ‘°κ±΄λΆ λ λλ§ (μΌνμ°μ°μ λμ κΆμ₯) */} <Show when={showCompleted() || !todo.done}> <div style={{ 'text-decoration': todo.done ? 'line-through' : 'none' }} onClick={() => toggleTodo(todo.id)} > {todo.text} </div> </Show> )} </For> </div> ); }
solid-chartjs. The key point is that there may be more parts we have to build ourselves.const { name } = user() like this, right?{user().name}. Or you can create a derived Signal with createMemo.For component receives the item through a callback function? The item itself isn't a Signal, so you have to access it inside the callback to keep reactivity, right?Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
const { name } = props, access it as props.name, or use the splitProps() utility.class instead of className, and for event handlers, onclick (lowercase) is also supported in place of onClick (camelCase). style must be passed as an object.createEffect.<Show> component is recommended instead of the ternary operator {condition ? <A/> : <B/>}. The ternary operator may evaluate both sides, which can lead to unintended behavior.