-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forward ref to
<PrismicNextImage>
- Loading branch information
1 parent
a8ed344
commit 2666f1f
Showing
6 changed files
with
125 additions
and
42 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
e2e-projects/app-router/app/PrismicNextImage/client/ClientTest.tsx
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,18 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { ImageField } from "@prismicio/client"; | ||
import { PrismicNextImage } from "@prismicio/next"; | ||
|
||
export function ClientTest(props: { field: ImageField }) { | ||
const { field } = props; | ||
|
||
const [ref, setRef] = useState<Element | null>(null); | ||
|
||
return ( | ||
<p> | ||
<PrismicNextImage ref={setRef} field={field} /> | ||
<span data-testid="ref">tagname: {ref?.tagName}</span> | ||
</p> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
e2e-projects/app-router/app/PrismicNextImage/client/page.tsx
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,14 @@ | ||
import { isFilled } from "@prismicio/client"; | ||
import assert from "assert"; | ||
|
||
import { createClient } from "@/prismicio"; | ||
import { ClientTest } from "./ClientTest"; | ||
|
||
export default async function Page() { | ||
const client = await createClient(); | ||
const { data: tests } = await client.getSingle("image_test"); | ||
|
||
assert(isFilled.image(tests.filled)); | ||
|
||
return <ClientTest field={tests.filled} />; | ||
} |
35 changes: 35 additions & 0 deletions
35
e2e-projects/pages-router/pages/PrismicNextImage/client.tsx
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,35 @@ | ||
import { useState } from "react"; | ||
import { GetServerSidePropsContext, InferGetServerSidePropsType } from "next"; | ||
import { PrismicNextImage } from "@prismicio/next/pages"; | ||
import { isFilled } from "@prismicio/client"; | ||
import assert from "assert"; | ||
|
||
import { createClient } from "@/prismicio"; | ||
|
||
export default function Page({ | ||
field, | ||
}: InferGetServerSidePropsType<typeof getServerSideProps>) { | ||
const [ref, setRef] = useState<Element | null>(null); | ||
|
||
return ( | ||
<p> | ||
<PrismicNextImage ref={setRef} field={field} /> | ||
<span data-testid="ref">tagname: {ref?.tagName}</span> | ||
</p> | ||
); | ||
} | ||
|
||
export async function getServerSideProps({ req }: GetServerSidePropsContext) { | ||
const repositoryName = req.cookies["repository-name"]; | ||
assert( | ||
repositoryName && typeof repositoryName === "string", | ||
"A repository-name cookie is required.", | ||
); | ||
|
||
const client = createClient(repositoryName); | ||
const { data: tests } = await client.getSingle("image_test"); | ||
|
||
assert(isFilled.image(tests.filled)); | ||
|
||
return { props: { field: tests.filled } }; | ||
} |
File renamed without changes.
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