Skip to content

Commit 7e06fb8

Browse files
committed
doc: error handling example
1 parent b8e8acf commit 7e06fb8

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# SvelteFire
22

3-
Cybernetically enhanced Firebase apps 💪🔥
3+
[Cybernetically](https://svelte.dev/) enhanced [Firebase](https://firebase.google.com/) apps 💪🔥
44

55
## Basics
66

77
- Use Firebase declaratively in Svelte components.
8-
- Handle complex relational data with simple loading & fallback states.
8+
- Handle complex relational data between Auth and Firestore.
9+
- Built in loading & fallback states for async data. (Similar to React Suspense)
910
- Automatic data disposal to prevent memory/cost leaks, plus enhanced logging.
1011
- Automatic performance monitoring & Google Analytics.
1112

@@ -169,23 +170,43 @@ In most cases, state flows from *loading* -> *default*. For errors, non-existent
169170
Data loaded, yay 🍦!
170171

171172
<!-- Only shown when loading -->
172-
<div slot="loading">
173-
Loading...
174-
</div>
173+
<div slot="loading"></div>
175174

176175
<!-- Shown on error or if nothing loads after maxWait time-->
176+
<div slot="fallback"></div>
177+
</Doc>
178+
```
179+
180+
Error handling made easy:
181+
182+
```html
183+
<Doc {path} let:error>
184+
177185
<div slot="fallback">
178-
whoops!
186+
😔 This doc cannot be read {error}
187+
</div>
188+
</Doc>
189+
```
190+
191+
Loading state made easy:
192+
193+
```html
194+
<Doc {path}>
195+
196+
<div slot="loading">
197+
179198
</div>
180199
</Doc>
181200
```
182201

183202
You can bypass the loading state entirely by passing a `startWith` prop.
184203

185204
```html
186-
<Doc path={'foods/ice-cream'} startWith={ {flavor: 'vanilla'} }>
205+
<Doc {path} startWith={ {flavor: 'vanilla'} }>
187206
```
188207

208+
209+
189210
### Slot Props
190211

191212
[Slot props](https://svelte.dev/tutorial/slot-props) **pass data down** to children the component tree. SvelteFire has done the hard work to expose the data you will need in the UI. For example, `let:data` gives you access to the document data, while `={yourVar}` is the name you use to reference it in your code. The `data` is a plain object for showing data in the UI, while the `ref` is a Firestore `DocumentReference` used to execute writes.

0 commit comments

Comments
 (0)