Skip to content

Commit 85ca1d3

Browse files
committed
スクロールで質問例が変わらないようにする
1 parent afd29a8 commit 85ca1d3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

app/(docs)/@docs/[lang]/[pageId]/chatForm.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState, FormEvent, useEffect } from "react";
3+
import { useState, FormEvent, useEffect, useMemo } from "react";
44
// import useSWR from "swr";
55
// import {
66
// getQuestionExample,
@@ -30,11 +30,16 @@ export function ChatForm({ path, sectionContent, close }: ChatFormProps) {
3030
const router = useRouter();
3131
const streamingChatContext = useStreamingChatContext();
3232

33-
const exampleData = sectionContent
34-
.filter((s) => s.inView)
35-
.map((s) => s.question)
36-
.filter((qe) => qe !== undefined)
37-
.flat();
33+
const exampleData = useMemo(
34+
() =>
35+
sectionContent
36+
.filter((s) => s.inView)
37+
.map((s) => s.question)
38+
.filter((qe) => qe !== undefined)
39+
.flat(),
40+
// eslint-disable-next-line react-hooks/exhaustive-deps
41+
[]
42+
);
3843
// 質問フォームを開くたびにランダムに選び直し、
3944
// exampleData[Math.floor(exampleChoice * exampleData.length)] を採用する
4045
const [exampleChoice, setExampleChoice] = useState<number | undefined>(

0 commit comments

Comments
 (0)