-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from buildheadless/preview
Separate sanity server loader from client loader
- Loading branch information
Showing
12 changed files
with
83 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getSanityClient } from "~/lib/sanity/client"; | ||
import { useEnvironmentVariables } from "./useEnvironmentVariables"; | ||
import { useSanityPreviewMode } from "./useSanityPreviewMode"; | ||
|
||
export function useSanityClient() { | ||
const env = useEnvironmentVariables(); | ||
const sanityPreviewMode = useSanityPreviewMode(); | ||
const { client } = getSanityClient({ | ||
projectId: env?.SANITY_STUDIO_PROJECT_ID!, | ||
dataset: env?.SANITY_STUDIO_DATASET!, | ||
studioUrl: env?.SANITY_STUDIO_URL!, | ||
useStega: env?.SANITY_STUDIO_USE_STEGA!, | ||
apiVersion: env?.SANITY_STUDIO_API_VERSION!, | ||
useCdn: env?.NODE_ENV === "production", | ||
sanityPreviewMode, | ||
}); | ||
|
||
return client; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createQueryStore } from "@sanity/react-loader"; | ||
import { useSanityClient } from "./useSanityClient"; | ||
|
||
export function useSanityLoader() { | ||
const client = useSanityClient(); | ||
const queryStore = createQueryStore({ | ||
client, | ||
ssr: false, | ||
}); | ||
const { useLiveMode, useQuery } = queryStore; | ||
|
||
return { queryStore, useLiveMode, useQuery }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters