You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Signal's value starts out equal to the passed first argument `initialValue` (or undefined if there are no arguments).
42
-
The `createSignal` function returns a pair of functions as a two-element array: a getter (or accessor) and a setter.
43
-
In typical use, you would destructure this array into a named Signal like so:
54
+
## Parameters
44
55
45
-
```tsx
46
-
const [count, setCount] =createSignal(0)
47
-
const [ready, setReady] =createSignal(false)
48
-
```
56
+
### `value`
57
+
58
+
**Type:**`T` (optional)
59
+
60
+
Theinitialvalueforthesignal. Ifnoinitialvalueisprovided, thesignal's type is automatically extended with `undefined`.
61
+
62
+
### `options`
63
+
64
+
**Type:**`SignalOptions<T>` (optional)
65
+
66
+
Configurationobjectforthesignal.
49
67
50
-
Calling the getter (e.g., `count()` or `ready()`) returns the current value of the Signal.
68
+
#### `name`
51
69
52
-
Crucial to automatic dependency tracking, calling the getter within a tracking scope causes the calling function to depend on this Signal, so that function will rerun if the Signal gets updated.
70
+
**Type:**`string` (optional)
53
71
54
-
Calling the setter (e.g., `setCount(nextCount)` or `setReady(nextReady)`) sets the Signal's value and updates the Signal (triggering dependents to rerun) if the value actually changed (see details below).
55
-
The setter takes either the new value for the signal or a function that maps the previous value of the signal to a new value as its only argument.
56
-
The updated value is also returned by the setter. As an example:
|`equals`|`false \| ((prev: T, next: T) => boolean)`|`===`| A function that determines whether the Signal's value has changed. If the function returns true, the Signal's value will not be updated and dependents will not rerun. If the function returns false, the Signal's value will be updated and dependents will rerun. |
100
-
|`name`|`string`|| A name for the Signal. This is useful for debugging. |
101
-
|`internal`|`boolean`|`false`| If true, the Signal will not be accessible in the devtools. |
131
+
## AdvancedUsage
102
132
103
-
### `equals`
133
+
### Usingacustomequalityfunction
104
134
105
-
The `equals` option can be used to customize the equality check used to determine whether the Signal's value has changed.
106
-
By default, the equality check is a strict equality check (`===`).
107
-
If you want to use a different equality check, you can pass a custom function as the `equals` option.
108
-
The custom function will be called with the previous and next values of the Signal as arguments.
109
-
If the function returns true, the Signal's value will not be updated and dependents will not rerun.
110
-
If the function returns false, the Signal's value will be updated and dependents will rerun.
Whenyoucalltheaccessorfunction within a reactive context (likeinside [`createEffect`](/reference/basic-reactivity/create-effect) or a component's JSX), it automatically establishes a dependency relationship.
188
+
Any subsequent calls to the setter will trigger updates only to the specific computations that depend on that signal.
0 commit comments