Skip to content

Commit a67220a

Browse files
committed
update titles and reactivity basics page
1 parent 20cf242 commit a67220a

File tree

10 files changed

+175
-85
lines changed

10 files changed

+175
-85
lines changed

src/routes/components/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"title": "Components",
3-
"pages": []
3+
"pages": ["intro.md"]
44
}

src/routes/components/intro.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "Intro to Components"
3+
order: 1
4+
---
5+
6+
[TODO]
7+
8+
## Component lifecycle
9+
10+
[TODO]

src/routes/reactivity/basics.mdx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: "Reactivity Basics"
3+
order: 1
4+
---
5+
6+
7+
Reactivity is the foundation of Solid.
8+
It’s the programming model where **changes in data automatically update the parts of your app that depend on it**.
9+
10+
Solid’s approach is **fine-grained**: instead of re-rendering entire components, only the exact parts of the DOM that depend on a value update. This makes applications efficient and responsive, even as they grow.
11+
12+
## Core Principles of Reactivity
13+
14+
Solid’s reactivity is built on three key ideas: **signals, subscribers, and tracking scopes**.
15+
Together, these create a system where updates are precise, automatic, and efficient.
16+
17+
### Signals: Reactive Values
18+
19+
A **signal** is a reactive value container.
20+
They consist of 2 parts:
21+
- **Getter** → reads the current value.
22+
- **Setter** → updates the value and notifies dependents.
23+
24+
```tsx
25+
const [count, setCount] = createSignal(0);
26+
27+
console.log(count()); // 0
28+
setCount(1);
29+
console.log(count()); // 1
30+
```
31+
32+
Signals can hold any type of value:
33+
- primitives (string, number, boolean)
34+
- objects and arrays
35+
- application state (user, theme, current page)
36+
37+
Learn more in the [Signals page](/reactivity/signals).
38+
39+
### Subscribers: Reactive Consumers
40+
41+
If signals are the **source of truth**, subscribers are the **reactive consumers**.
42+
43+
A subscriber is any function or construct that reads a signal inside a tracking scope and automatically re-runs whenever it changes.
44+
This is what makes Solid’s reactivity *fine-grained*: only the subscribers that depend on a signal update, not the entire component.
45+
46+
How subscribers work:
47+
1. **Observation** → subscriber runs and reads signals.
48+
2. **Dependency tracking** → those signals register the subscriber.
49+
3. **Response** → when a signal changes, the subscriber re-runs.
50+
51+
### Tracking Scopes: Connecting Signals & Subscribers
52+
53+
A **tracking scope** is the environment where Solid records which signals are being used.
54+
When a signal is read within a tracking scope, it registers the current subscriber as a dependency.
55+
Once that signal changes, it will notify the subscriber to re-run and update accordingly.
56+
57+
Tracking scopes within Solid include:
58+
- Component render functions (JSX return values)
59+
- Reactive computations (e.g., `createMemo`)
60+
- Effects (e.g., `createEffect`)
61+
62+
Example of a tracking vs non-tracking scope:
63+
64+
```tsx
65+
import { createSignal } from "solid-js";
66+
67+
function Counter() {
68+
const [count, setCount] = createSignal(0);
69+
70+
console.log(count()) // ❌ Not tracked — runs once
71+
72+
return (
73+
<div>
74+
<p>Count: {count()}</p> {/* ✅ tracked automatically - re-runs on update */}
75+
<button onClick={() => setCount(count() + 1)}>Increment</button>
76+
</div>
77+
);
78+
}
79+
```
80+
81+
Tracking scopes are what enable **precise DOM updates**: only parts of the UI that depend on signals re-run, not the entire component.
82+
You can learn more about [component lifecycles in the Intro to Components page](/components/intro).
83+
84+
85+
## Related pages
86+
- [Signals](/reactivity/signals)
87+
- [Reactive Side Effects](/reactivity/effects)
88+
- [Introduction to Components](/components/intro)

src/routes/reactivity/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": "Reactivity",
33
"pages": [
4-
"overview.mdx",
4+
"basics.mdx",
55
"signals.mdx",
66
"memos.mdx",
77
"effects.mdx",

src/routes/reactivity/effects.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Effects"
2+
title: "Derived Reactive Values"
33
order: 4
44
---
55

src/routes/reactivity/memos.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Memos"
2+
title: "Memoized Computations"
33
order: 3
44
---
55

src/routes/reactivity/overview.mdx

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/routes/reactivity/resources.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Resources"
2+
title: "Handling Async Data"
33
order: 6
44
---
55

src/routes/reactivity/signals.mdx

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,74 @@ title: "Signals"
33
order: 2
44
---
55

6-
[TODO:
7-
Concept page on signals
8-
- Any complex parts should be moved to reference section
9-
- Move any concept bits from reference section into here
10-
]
6+
Signals are the **primary way to manage state** in a Solid application.
7+
They store values, notify dependents when those values change, and form the [foundation of reactivity](/reactivity/overview).
8+
9+
You can use signals for any kind of state:
10+
- simple values (strings, numbers)
11+
- complex values (objects, arrays)
12+
- application state (current user, theme, page, etc.)
13+
14+
## What is a Signal?
15+
16+
A **signal** is a reactive value container.
17+
- It holds a value.
18+
- It provides a **getter** to read the value.
19+
- It provides a **setter** to update the value.
20+
- When the value changes, any reactive computations that depend on it are updated automatically.
21+
22+
They can be thought of as a **reactive variable**.
23+
24+
## Create a Signal
25+
26+
27+
Use [`createSignal`](/reference/basic-reactivity/create-signal) from `solid-js`:
28+
29+
```tsx
30+
import { createSignal } from "solid-js";
31+
32+
const [count, setCount] = createSignal(0);
33+
// ^ getter ^ setter
34+
```
35+
36+
:::note
37+
The [getter, setter] syntax uses [array destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)().
38+
:::
39+
40+
41+
## Read a Signal's Value
42+
43+
To read the current value of a signal, simply call the getter function:
44+
45+
```tsx
46+
console.log(count()); // 0
47+
```
48+
49+
## Update a Signal's Value
50+
51+
To update the value of a signal, call the setter function with the new value:
52+
53+
```tsx
54+
setCount(1);
55+
console.log(count()); // 1
56+
```
57+
58+
## Reactivity in Action
59+
60+
Signals are **reactive**: when used inside a tracking scope, they automatically notify dependents when updated.
61+
62+
```tsx
63+
function Counter() {
64+
const [count, setCount] = createSignal(0);
65+
const increment = () => setCount(prev => prev + 1);
66+
67+
return (
68+
<div>
69+
<span>Count: {count()}</span> {/* Updates when `count` changes */}
70+
<button onClick={increment}>Increment</button>
71+
</div>
72+
);
73+
}
74+
```
75+
76+
:::

src/routes/reactivity/stores.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
title: "Stores"
2+
title: "Reactive State Management"
33
order: 5
44
---

0 commit comments

Comments
 (0)