Skip to content

Commit 6f950dc

Browse files
authored
blog: more fixes to the react table blog (#333)
* blog: update to react table post * update
1 parent 4d5fcd9 commit 6f950dc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

blog/react-table/index.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ A [Prisma schema file](https://github.com/ymc9/react-query-table-zenstack/blob/m
9292

9393
SQL databases are not meant to be consumed from the frontend. You need an API to mediate. You can build such an API in many ways, but here we'll use [ZenStack](https://zenstack.dev) to "unbuild" it. ZenStack is a full-stack toolkit built above Prisma, and one of the cool things it does is to automagically derive a backend API from the schema.
9494

95-
Setting ZenStack up is very easy:
95+
Setting ZenStack up is straightforward:
9696

9797
1. Run `npx zenstack init` to prep the project. It copies the `schema.prisma` file into `schema.zmodel` - which is the schema file used by ZenStack. ZModel is a superset of Prisma schema.
9898

@@ -133,7 +133,7 @@ I know a big **🚨 NO THIS IS NOT SECURE 🚨** is flashing in your mind. Hold
133133

134134
Having a free API is cool, but writing `fetch` to call it is cumbersome. How about some free query hooks? Yes, add the `@zenstackhq/tanstack-query` plugin to the ZModel schema, and you'll have a set of fully typed React Query hooks generated for each model:
135135

136-
```ts title="schema.zmodel"
136+
```zmodel title="schema.zmodel"
137137
plugin hooks {
138138
provider = '@zenstackhq/tanstack-query'
139139
target = 'react'
@@ -191,13 +191,12 @@ const columns = [
191191
];
192192

193193
export const OrderDetails = () => {
194+
// fetch data with query hooks
194195
const { data } = useFindManyOrderDetail({
195196
...queryInclude,
196-
orderBy: computeOrderBy(),
197-
skip: pagination.pageIndex * pagination.pageSize,
198-
take: pagination.pageSize,
199197
});
200198

199+
// create a table instance
201200
const table = useReactTable({
202201
data: orders ?? [],
203202
columns,
@@ -206,10 +205,12 @@ export const OrderDetails = () => {
206205
}
207206
```
208207

209-
We can then render the table with some basic TSX:
208+
We can then render the table with some basic tsx:
210209

211210
```tsx
212211
export const OrderDetails = () => {
212+
...
213+
213214
return (
214215
<table>
215216
<thead>
@@ -291,7 +292,6 @@ Also, update the hooks call to respect the pagination state:
291292
```tsx
292293
const { data } = useFindManyOrderDetail({
293294
...queryInclude,
294-
orderBy: computeOrderBy(),
295295
// highlight-start
296296
skip: pagination.pageIndex * pagination.pageSize,
297297
take: pagination.pageSize,
@@ -324,21 +324,21 @@ This part well demonstrates the value of "headless" UI. You don't need to manage
324324

325325
We've got a pretty cool table end-to-end working now, with roughly 200 lines of code. Less code is only one of the benefits of this combination. It also provides excellent flexibility in every layer of the stack:
326326

327-
- Prisma's query
327+
- **Prisma's query**
328328

329329
Prisma is known for its concise yet powerful query API. It allows you to do complex joins and aggregations without writing SQL. In our example, our table shows data from five tables, and we barely noticed the complexity.
330330

331-
- ZenStack's access control
331+
- **ZenStack's access control**
332332

333333
Remember I said we'll get back to the security issue? A real-world API must have an authorization mechanism with it. ZenStack's real power lies in its ability to define access control rules in the data schema. You can define rules like rejecting anonymous users or showing only the orders of the current login employee, etc. Read more details [here](/docs/the-complete-guide/part1/access-policy/).
334334

335-
- React Query's fetching
335+
- **React Query's fetching**
336336

337-
React Query provides great flexibility around how data is fetched, cached, and invalidated. Leverage its power to build a highly responsive UI and reduce the load on the database at same time.
337+
React Query provides great flexibility around how data is fetched, cached, and invalidated. Leverage its power to build a highly responsive UI and reduce the load on the database at same time.
338338

339-
- React Table's state management
339+
- **React Table's state management**
340340

341-
React Table has every aspect of a table's state organized for you. It provides a solid pattern to follow without limiting how you render the table UI.
341+
React Table has every aspect of a table's state organized for you. It provides a solid pattern to follow without limiting how you render the table UI.
342342

343343
## Conclusion
344344

0 commit comments

Comments
 (0)