From 80443caaad44dd8401ee5e1434e509f03364f63f Mon Sep 17 00:00:00 2001 From: Stan Wohlwend Date: Wed, 31 Jul 2024 11:10:27 -0700 Subject: [PATCH] Update docs --- docs/fern/docs/pages/concepts/stack-app.mdx | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/fern/docs/pages/concepts/stack-app.mdx b/docs/fern/docs/pages/concepts/stack-app.mdx index ff5bf6d4b..168c42458 100644 --- a/docs/fern/docs/pages/concepts/stack-app.mdx +++ b/docs/fern/docs/pages/concepts/stack-app.mdx @@ -15,6 +15,28 @@ You will see that most of the asynchronous functions on `StackApp` come in two f Normally, you would choose between the two based on whether you are in a React Server Component or a React Client Component. However, there are some scenarios where you use `getXyz` on the client, for example as the callback of an `onClick` handler. +```tsx +// server-component.tsx +async function ServerComponent() { + const app = stackServerApp; + // returns a Promise, must be awaited + const user = await app.getUser(); + + return
{user.displayName}
; +} + + +// client-component.tsx +"use client"; +function ClientComponent() { + const app = useApp(); + // returns the value directly + const user = app.useUser(); + + return
{user.displayName}
; +} +``` + ## Client vs. server `StackClientApp` is the app which contains everything needed to build a frontend application, for example the own user object. It requires a publishable client key in its initialization (usually set by the `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY` environment variable). @@ -23,4 +45,6 @@ Normally, you would choose between the two based on whether you are in a React S There is also a third type, `StackAdminApp`, but it is rarely used. It is meant for internal tools that have special requirements, and can edit the Stack project configuration. This is useful for configuring Stack programmatically, for example with Terraform. -Some of the functions have different return types; for example, `StackClientApp.getUser()` returns a `Promise` while `StackServerApp.getUser()` returns a `Promise`. The `Server` or `Admin` prefixes indicates that the object contains server-/admin-only functionality respectively. + + Some of the functions have different return types; for example, `StackClientApp.getUser()` returns a `Promise` while `StackServerApp.getUser()` returns a `Promise`. The `Server` or `Admin` prefixes indicates that the object contains server-/admin-only functionality. +