Skip to content

Commit f6d64ab

Browse files
committed
docs: getters in docs
1 parent eb7e668 commit f6d64ab

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

docs/guide/realtime-data.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,48 @@ const contact = useDocument(contactSource)
8181
This way, when the route changes, the document will be updated to the new one, automatically unsubscribing from the previous one and subscribing to the new one.
8282

8383
::: tip
84-
If you can't use a `computed()`, use `shallowRef()`s instead of `ref()`s to store the data sources. This is because `shallowRef()` doesn't try to recursively observe the object it's given, which in the case of a Firebase data source, would be worse in terms of performance.
84+
85+
`contactSource` can either be a _getter_, a `computed()`, or a `ref()`. If you are using a `ref()`, make sure to use `shallowRef()` instead of `ref()` for better performance.
86+
87+
```ts
88+
const asRef = shallowRef(dbRef(db, 'contacts/' + route.params.id))
89+
useDocument(asRef)
90+
const asComputed = computed(() => dbRef(db, 'contacts/' + route.params.id))
91+
useDocument(asComputed)
92+
// a getter is the lightest option
93+
useDocument(() => dbRef(db, 'contacts/' + route.params.id))
94+
```
95+
8596
:::
8697

98+
On top of that, VueFire also allows `null` as a value for the data source. This is useful when you want to start observing a document or collection later in the lifecycle of your component, or if you cannot computed a valid document path, e.g. when the user is not logged in:
99+
100+
<FirebaseExample>
101+
102+
```ts
103+
const user = useCurrentUser()
104+
const myContactList = useCollection(() =>
105+
user.value
106+
? // Firebase will error if a null value is passed to `collection()`
107+
collection(db, 'users', user.value.id, 'contacts')
108+
: // this will be considered as no data source
109+
null
110+
)
111+
```
112+
113+
```ts
114+
const user = useCurrentUser()
115+
const myContactList = useDatabaseList(() =>
116+
user.value
117+
? // Firebase will error if a null value is passed to `dbRef()`
118+
dbRef(db, 'users', user.value.id, 'contacts')
119+
: // this will be considered as no data source
120+
null
121+
)
122+
```
123+
124+
</FirebaseExample>
125+
87126
### Subscription state
88127

89128
All of the composables can also be destructured to access other useful data like _is the initial load still pending?_ or _did the subscription fail?_. You only need to destructure the returned value from the composables:

docs/guide/ssr.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Server Side Rendering (SSR)
22

3-
> Manually doing Server Side Rendering can get really complex, it is recommended to use Nuxt. Read the [Nuxt guide](/nuxt/getting-started.md), most of the things are already configured for you.
4-
5-
::: warning
6-
SSR support is still experimental. Please report any issues you find.
3+
:::tip
4+
Manually doing Server Side Rendering can get really complex, it is recommended to use Nuxt. Read the [Nuxt guide](/nuxt/getting-started.md), most of the things are already configured for you.
75
:::
86

97
## SSR with Vitesse

0 commit comments

Comments
 (0)