Skip to content

Commit

Permalink
docs(state): add guidance on signals as props (#6574)
Browse files Browse the repository at this point in the history
Co-authored-by: Giorgio Boa <35845425+gioboa@users.noreply.github.com>
  • Loading branch information
shairez and gioboa committed Jun 20, 2024
1 parent cfa1f21 commit e2b6895
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/docs/src/routes/docs/(qwik)/components/state/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contributors:
- aivarsliepa
- Balastrong
- Jemsco
- shairez
updated_at: '2023-10-04T21:48:45Z'
created_at: '2023-03-20T23:45:13Z'
---
Expand Down Expand Up @@ -73,6 +74,25 @@ export default component$(() => {

This example above shows how `useSignal()` can be used in a counter component to keep track of the count. Modifying the `count.value` property will cause the component to be updated automatically. For instance, when the property is changed in the button click handler as in the example above.

> **NOTE** If you just need to read the signal's value, don't pass the entire signal as a prop, instead pass only its value:
**Avoid:**

```tsx
const isClosedSig = useSignal(false);

return <Child isClosed={isClosedSig} />;
```

**Instead do:**

```tsx
const isClosedSig = useSignal(false);

return <Child isClosed={isClosedSig.value} />;
```


## `useStore()`

Works very similarly to `useSignal()`, but it takes an object as its initial value and the reactivity extends to nested objects and arrays by default. One can think of a store as a multiple-value signal or an object made of several signals.
Expand Down

0 comments on commit e2b6895

Please sign in to comment.