diff --git a/readme.md b/readme.md index 5952b5e..c02f82a 100644 --- a/readme.md +++ b/readme.md @@ -62,13 +62,13 @@ import { query } from 'sesh-cache-helper' import { prisma } from './prismaClient' export const getUserById = query( - async (userId: string) => { - const user = await prisma.user.findUnique({ - where: { id: userId }, - }) - return user - }, - (userId) => `getUserById-${userId}` + async (userId: string) => { + const user = await prisma.user.findUnique({ + where: { id: userId }, + }) + return user + }, + (userId) => `getUserById-${userId}` ) ``` @@ -103,14 +103,14 @@ import { query } from 'sesh-cache-helper' import { prisma } from './prismaClient' export const getUserById = query( - async (userId: string) => { - // Directly query the database using Prisma - const user = await prisma.user.findUnique({ - where: { id: userId }, - }) - return user - }, - (userId) => `getUserById-${userId}` + async (userId: string) => { + // Directly query the database using Prisma + const user = await prisma.user.findUnique({ + where: { id: userId }, + }) + return user + }, + (userId) => `getUserById-${userId}` ) ``` @@ -121,18 +121,18 @@ export const getUserById = query( import { getUserById } from '../../../queries' export default async function UserPage({ params }) { - const user = await getUserById(params.userId) - - if (!user) { - return
User not found.
- } - - return ( -
-

{user.name}

-

Email: {user.email}

-
- ) + const user = await getUserById(params.userId) + + if (!user) { + return
User not found.
+ } + + return ( +
+

{user.name}

+

Email: {user.email}

+
+ ) } ``` @@ -146,13 +146,13 @@ export default async function UserPage({ params }) { import { useBrowserSessionId } from 'sesh-cache-helper' export default function RootLayout({ children }) { - useBrowserSessionId() + useBrowserSessionId() - return ( - - {children} - - ) + return ( + + {children} + + ) } ``` @@ -167,13 +167,13 @@ Usage: import { useBrowserSessionId } from 'sesh-cache-helper' export default function RootLayout({ children }) { - useBrowserSessionId({ hasDisabledCookies: true }) // Disable cookies + useBrowserSessionId({ hasDisabledCookies: true }) // Disable cookies - return ( - - {children} - - ) + return ( + + {children} + + ) } ``` @@ -219,13 +219,13 @@ import { query } from 'sesh-cache-helper' import { prisma } from './prismaClient' export const getPostsByUser = query( - async (userId: string) => { - const posts = await prisma.post.findMany({ - where: { authorId: userId }, - }) - return posts - }, - (userId) => `getPostsByUser-${userId}` + async (userId: string) => { + const posts = await prisma.post.findMany({ + where: { authorId: userId }, + }) + return posts + }, + (userId) => `getPostsByUser-${userId}` ) ``` @@ -236,23 +236,23 @@ Using in a Server Component: import { getPostsByUser } from '../../../../lib/queries' export default async function UserPostsPage({ params }) { - const posts = await getPostsByUser(params.userId) - - return ( -
-

Posts by User {params.userId}

- {posts.length === 0 ? ( -

No posts found.

- ) : ( - posts.map((post) => ( -
-

{post.title}

-

{post.content}

-
- )) - )} -
- ) + const posts = await getPostsByUser(params.userId) + + return ( +
+

Posts by User {params.userId}

+ {posts.length === 0 ? ( +

No posts found.

+ ) : ( + posts.map((post) => ( +
+

{post.title}

+

{post.content}

+
+ )) + )} +
+ ) } ``` @@ -283,14 +283,14 @@ Using in a Server Component: import { getExternalData } from '../../../lib/queries' export default async function DataPage({ params }) { - const data = await getExternalData(params.endpoint) - - return ( -
-

Data for {params.endpoint}

-
{JSON.stringify(data, null, 2)}
-
- ) + const data = await getExternalData(params.endpoint) + + return ( +
+

Data for {params.endpoint}

+
{JSON.stringify(data, null, 2)}
+
+ ) } ```