Next.js Discord

Discord Forum

Retrieve latest DB data on page reload (by the browser)

Unanswered
Broad-snouted Caiman posted this in #help-forum
Open in Discord
Broad-snouted CaimanOP
Hello, I am new to Next.js. Although it seems trivial, I am unable to achieve the following: I am using Next.js 14 with App Router, and I am fetching some data from my database using Prisma, then passing it down to my component. The problem I am facing is that if I change the database and then visit my page and perform a hard refresh (CMD + Shift + R), the page does not get updated. Is there a way to make this happen? I still want to use the benefits of server rendering, but I want it to pick up new changes if the user forces a reload.

import { CustomComponent } from '@/components/custom'
import styles from './styles.module.css'
import { fetchData } from '@/lib/data';

export default async function ExamplePage() {
  const data = await fetchData('unique-identifier')

  return (
    <div className={styles.container}>
      <CustomComponent data={data}/>
    </div>
  )
}

1 Reply

Giant resin bee
In your page file write this line

export const dynamic = "force-dynamic"