Skip to content

Commit f0735c6

Browse files
committed
Added presence documentation
1 parent ccef147 commit f0735c6

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

packages/presence/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,42 @@ const SecondExample = () => {
124124
};
125125
```
126126

127+
### `createPresence` with a store
128+
129+
`createPresence`'s first argument must be an `Accessor` — a function. Reading a store property directly (`store.panelOpen`) passes its current value once and won't update reactively; wrap the access in a function (`() => store.panelOpen`) so `createPresence` can subscribe to changes:
130+
131+
```tsx
132+
const ThirdExample = () => {
133+
const [store, setStore] = createStore({ panelOpen: true });
134+
135+
// ✅ wrapped in an accessor
136+
const { isVisible, isMounted } = createPresence(() => store.panelOpen, {
137+
transitionDuration: 500,
138+
});
139+
140+
// ❌ createPresence(store.panelOpen, { transitionDuration: 500 })
141+
// — this is a boolean, not an Accessor<boolean>, and won't type-check
142+
143+
return (
144+
<div>
145+
<button onclick={() => setStore("panelOpen", open => !open)}>
146+
{store.panelOpen ? "Hide" : "Show"} panel
147+
</button>
148+
<Show when={isMounted()}>
149+
<div
150+
style={{
151+
transition: "all .5s ease",
152+
opacity: isVisible() ? "1" : "0",
153+
}}
154+
>
155+
I am the panel!
156+
</div>
157+
</Show>
158+
</div>
159+
);
160+
};
161+
```
162+
127163
### `createPresence` options API
128164

129165
```ts

0 commit comments

Comments
 (0)