© 2019-2026 OPTiM Corp. All rights reserved. 20
Next.js15での実装例
'use client'
import { useEffect, useState } from 'react'
type Product = { id: string; name: string }
export function RecommendedProductsClient() {
const [items, setItems] = useState(null)
useEffect(() => {
;(async () => {
const res = await fetch('/api/recommended', {
method: 'GET',
credentials: 'include', // cookie を送る
cache: 'no-store',
})
setItems(await res.json())
})()
}, [])
if (!items) return
読み込み中…
return
{items.map((x) => - {x.name}
)}
}
←アプリ仕様