You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sdks/typescript/quickstart.md
+31-17Lines changed: 31 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -384,27 +384,42 @@ module_bindings
384
384
└── user_type.ts
385
385
```
386
386
387
-
With `spacetime generate` we have generated TypeScript types derived from the types you specified in your module, which we can conveniently use in our client. We've placed these in the `module_bindings` folder. The main entry to the SpacetimeDB API is the `DBConnection`, a type which manages a connection to a remote database. Let's import it and a few other types into our `client/src/App.tsx`.
387
+
With `spacetime generate` we have generated TypeScript types derived from the types you specified in your module, which we can conveniently use in our client. We've placed these in the `module_bindings` folder. The main entry to the SpacetimeDB API is the `DbConnection`, a type which manages a connection to a remote database. Let's import it and a few other types into our `client/src/App.tsx`.
388
388
389
389
```tsx
390
-
import { DBConnection, EventContext, Message, User } from'./module_bindings';
390
+
import { DbConnection, EventContext, Message, User } from'./module_bindings';
@@ -455,12 +469,12 @@ In the `onConnect` function we are also subscribing to the `message` and `user`
455
469
456
470
### Accessing the Data
457
471
458
-
Once SpacetimeDB is connected, we can easily access the data in the client cache using our `DBConnection`. The `conn.db` field allows you to access all of the tables of your database. Those tables will contain all data requested by your subscription configuration.
472
+
Once SpacetimeDB is connected, we can easily access the data in the client cache using our `DbConnection`. The `conn.db` field allows you to access all of the tables of your database. Those tables will contain all data requested by your subscription configuration.
459
473
460
474
Let's create custom React hooks for the `message` and `user` tables. Add the following code above your `App` component:
461
475
462
476
```tsx
463
-
function useMessages(conn:DBConnection|null):Message[] {
477
+
function useMessages(conn:DbConnection|null):Message[] {
@@ -648,7 +662,7 @@ Our `user` table includes all users not just online users, so we want to take ca
648
662
649
663
Here we post a message saying a new user has connected if the user is being added to the `user` table and they're online, or if an existing user's online status is being set to "online".
650
664
651
-
Note that `onInsert` and `onDelete` callbacks takes two arguments: an `EventContext` and the row. The `EventContext` can be used just like the `DBConnection` and has all the same access functions, in addition to containing information about the event that triggered this callback. For now, we can ignore this argument though, since we have all the info we need in the user rows.
665
+
Note that `onInsert` and `onDelete` callbacks takes two arguments: an `EventContext` and the row. The `EventContext` can be used just like the `DbConnection` and has all the same access functions, in addition to containing information about the event that triggered this callback. For now, we can ignore this argument though, since we have all the info we need in the user rows.
0 commit comments