-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CodeSandbox demo of deep store and sync docs
- Loading branch information
1 parent
b64de0c
commit 2e84404
Showing
2 changed files
with
49 additions
and
18 deletions.
There are no files selected for viewing
31 changes: 23 additions & 8 deletions
31
packages/docs/src/routes/demo/state/counter-store-deep/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
import { component$, useStore } from '@builder.io/qwik'; | ||
|
||
export default component$(() => { | ||
const store = useStore( | ||
{ | ||
nested: { fields: { are: 'not tracked' } }, | ||
const store = useStore({ | ||
nested: { | ||
fields: { are: 'also tracked' }, | ||
}, | ||
{ deep: true } | ||
); | ||
list: ['Item 1'], | ||
}); | ||
|
||
return ( | ||
<> | ||
<p>{store.nested.fields.are}</p> | ||
<button onClick$={() => (store.nested.fields.are = 'tracked')}> | ||
<button | ||
onClick$={() => { | ||
// Even though we are mutating a nested object, this will trigger a re-render | ||
store.nested.fields.are = 'tracked'; | ||
}} | ||
> | ||
Clicking me works because store is deep watched | ||
</button> | ||
<br /> | ||
<button onClick$={() => (store.nested = { fields: { are: 'tracked' } })}> | ||
Click me still works | ||
<button | ||
onClick$={() => { | ||
// Because store is deep watched, this will trigger a re-render | ||
store.list.push(`Item ${store.list.length}`); | ||
}} | ||
> | ||
Add to list | ||
</button> | ||
<ul> | ||
{store.list.map((item) => ( | ||
<li>{item}</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters