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
// Any signals or stores accessed inside the task will be tracked
8880
8869
const count =track(() =>store.count);
8870
+
// For stores you can also pass the store and specify the property
8871
+
track(store, "count");
8881
8872
// You can also pass a signal to track() directly
8882
8873
const signalCount =track(signal);
8883
8874
store.doubleCount =count+signalCount;
@@ -9010,9 +9001,7 @@ T
9010
9001
9011
9002
## useAsync$
9012
9003
9013
-
Creates an AsyncSignal which is calculated from the given async function. If the function uses reactive state, and that state changes, the AsyncSignal is recalculated, and if the result changed, all tasks which are tracking the AsyncSignal will be re-run and all components that read the AsyncSignal will be re-rendered.
9014
-
9015
-
The function must not have any side effects, as it can run multiple times.
9004
+
Creates an AsyncSignal which holds the result of the given async function. If the function uses `track()` to track reactive state, and that state changes, the AsyncSignal is recalculated, and if the result changed, all tasks which are tracking the AsyncSignal will be re-run and all subscribers (components, tasks etc) that read the AsyncSignal will be updated.
9016
9005
9017
9006
If the async function throws an error, the AsyncSignal will capture the error and set the `error` property. The error can be cleared by re-running the async function successfully.
9018
9007
@@ -9024,7 +9013,7 @@ If the value has been resolved, but the async function is re-running, reading th
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-async.ts)
9074
9063
@@ -9706,6 +9695,43 @@ T \| undefined
9706
9695
9707
9696
## useSignal
9708
9697
9698
+
Creates an object with a single reactive `.value` property, that Qwik can track across serializations.
9699
+
9700
+
Use it to create state for your application. The object has a getter and setter to track reads and writes of the `.value` property. When the value changes, any functions that read from it will re-run.
9701
+
9702
+
Prefer `useSignal` over `useStore` when possible, as it is more efficient.
9703
+
9704
+
### Example
9705
+
9706
+
```tsx
9707
+
constSignals = component$(() => {
9708
+
const counter =useSignal(1);
9709
+
const text =useSignal('changeme');
9710
+
const toggle =useSignal(false);
9711
+
9712
+
// useSignal() can also accept a function to calculate the initial value
// pass signal values as the value, the optimizer will make it pass the signal
9722
+
}
9723
+
<Childstate={state.value} />
9724
+
{
9725
+
// signals can be bound to inputs. A property named `bind:x` implies that the property
9726
+
isasignal
9727
+
}
9728
+
<inputtype="text"bind:value={text} />
9729
+
<inputtype="checkbox"bind:checked={toggle} />
9730
+
</div>
9731
+
);
9732
+
});
9733
+
```
9734
+
9709
9735
```typescript
9710
9736
useSignal:UseSignal;
9711
9737
```
@@ -9714,6 +9740,43 @@ useSignal: UseSignal;
9714
9740
9715
9741
## UseSignal
9716
9742
9743
+
Creates an object with a single reactive `.value` property, that Qwik can track across serializations.
9744
+
9745
+
Use it to create state for your application. The object has a getter and setter to track reads and writes of the `.value` property. When the value changes, any functions that read from it will re-run.
9746
+
9747
+
Prefer `useSignal` over `useStore` when possible, as it is more efficient.
9748
+
9749
+
### Example
9750
+
9751
+
```tsx
9752
+
constSignals = component$(() => {
9753
+
const counter =useSignal(1);
9754
+
const text =useSignal('changeme');
9755
+
const toggle =useSignal(false);
9756
+
9757
+
// useSignal() can also accept a function to calculate the initial value
// pass signal values as the value, the optimizer will make it pass the signal
9767
+
}
9768
+
<Childstate={state.value} />
9769
+
{
9770
+
// signals can be bound to inputs. A property named `bind:x` implies that the property
9771
+
isasignal
9772
+
}
9773
+
<inputtype="text"bind:value={text} />
9774
+
<inputtype="checkbox"bind:checked={toggle} />
9775
+
</div>
9776
+
);
9777
+
});
9778
+
```
9779
+
9717
9780
```typescript
9718
9781
useSignal:UseSignal;
9719
9782
```
@@ -9722,9 +9785,13 @@ useSignal: UseSignal;
9722
9785
9723
9786
## useStore
9724
9787
9725
-
Creates an object that Qwik can track across serializations.
9788
+
Creates a reactive object that Qwik can track across serialization.
9789
+
9790
+
Use it to create state for your application. The returned object is a Proxy that tracks reads and writes. When any of the properties change, the functions that read those properties will re-run.
9791
+
9792
+
`Store`s are deep by default, meaning that any objects assigned to properties will also become `Store`s. This includes arrays.
9726
9793
9727
-
Use `useStore` to create a state for your application. The returned object is a proxy that has a unique ID. The ID of the object is used in the `QRL`s to refer to the store.
9794
+
Prefer `useSignal` over `useStore` when possible, as it is more efficient.
0 commit comments