Skip to content

Commit 5e9e9fa

Browse files
committed
focused signals page
1 parent eae150b commit 5e9e9fa

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

old pages/concepts/signals.mdx

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,45 @@ tags:
1111
version: '1.0'
1212
---
1313

14-
Signals are the primary means of [managing state](/concepts/intro-to-reactivity#state-management) in your Solid application.
15-
They provide a way to store and update values, and are the foundation of [reactivity](/concepts/intro-to-reactivity) in Solid.
14+
Signals are the **core primitive for state** in Solid.
15+
They provide a way to store a value, read it, and update it.
16+
When a signal changes, anything that depends on it will update automatically.
1617

17-
Signals can be used to represent any kind of state in your application, such as the current user, the current page, or the current theme.
18-
This can be any value, including primitive values such as strings and numbers, or complex values such as objects and arrays.
18+
Signals can represent any kind of state in your application:
19+
- simple values like numbers or strings
20+
- complex values like objects or arrays
21+
- application state such as the current user, theme, or page
22+
23+
For an overview of how signals fit into Solid’s reactive model, see [Reactivity Basics](/reactivity/basics).
1924

2025
## Creating a signal
2126

22-
You can create a signal by calling the [`createSignal`](/reference/basic-reactivity/create-signal) function, which is imported from `solid-js`.
23-
This function takes an initial value as an argument, and returns a pair of functions: a **getter** function, and a **setter** function.
27+
Use [`createSignal`](/reference/basic-reactivity/create-signal) from `solid-js` to create a signal.
28+
It returns a pair of functions:
29+
- a **getter** to read the value
30+
- a **setter** to update the value
2431

2532
```jsx
2633
import { createSignal } from "solid-js";
2734

2835
const [count, setCount] = createSignal(0);
29-
// ^ getter ^ setter
36+
// ^ getter ^ setter
3037
```
3138

32-
:::note
33-
The syntax using `[` and `]` is called [array destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment).
39+
:::note
40+
The syntax using `[` and `]` is called [array destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment).
3441

3542
This lets you extract values from the array.
3643
In the context of `createSignal`, the first value is the getter function, and the second value is the setter function.
37-
3844
:::
3945

4046
## Accessing values
4147

4248
The getter function returned by `createSignal` is used to access the value of the signal.
43-
You call this function with no arguments to get the current value of the signal:
49+
Call the getter function with no arguments to read the current value:
4450

4551
```jsx
46-
console.log(count()); // output: 0
52+
console.log(count()); // 0
4753
```
4854

4955
## Updating values
@@ -54,22 +60,21 @@ This function takes an argument that represents the new value of the signal:
5460
```jsx
5561
setCount(count() + 1);
5662

57-
console.log(count()); // output: 1
63+
console.log(count()); // 1
5864
```
5965

6066
The setter function can also take a function that passes the previous value.
6167

6268
```jsx
6369
setCount((prevCount) => prevCount + 1);
6470

65-
console.log(count()); // output: 1
71+
console.log(count()); // 1
6672
```
6773

6874
## Reactivity
6975

70-
Signals are reactive, which means that they automatically update when their value changes.
71-
When a signal is called within a [tracking scope](/concepts/intro-to-reactivity#tracking-changes), the signal adds the dependency to a list of subscribers.
72-
Once a signal's value changes, it notifies all of its dependencies of the change so they can re-evaluate their values and update accordingly.
76+
Signals are **reactive**, which means that they automatically update when their value changes.
77+
For example, using a signal inside JSX automatically makes the DOM update when the signal changes:
7378

7479
```jsx
7580
function Counter() {
@@ -87,12 +92,13 @@ function Counter() {
8792
}
8893
```
8994

90-
:::note
91-
A tracking scope can be created by [`createEffect`](/reference/basic-reactivity/create-effect) or [`createMemo`](/reference/basic-reactivity/create-memo), which are other Solid primitives.
92-
93-
Both functions subscribe to the signals accessed within them, establishing a dependency relationship.
94-
Once this relationship is established, the function is notified whenever the signal changes.
95+
To learn how signals connect to effects and tracking scopes, see:
96+
- [Reactive Side Effects](/reactivity/effects)
97+
- [Memoized Computations](/reactivity/memo)
9598

96-
:::
99+
## Related Pages
97100

98-
To learn more about how to use Signals in your application, visit our [state management guide](/guides/state-management).
101+
- [Reactivity Basics](/reactivity/basics)
102+
- [Reactive Side Effects](/reactivity/effects)
103+
- [Memoized Computations](/reactivity/memo)
104+
- [Introduction to Components](/components/intro)

0 commit comments

Comments
 (0)