Skip to content

Commit

Permalink
add noStore() unstable utility to refetch cache in NEXT.js for da…
Browse files Browse the repository at this point in the history
  • Loading branch information
bozzhik committed Apr 6, 2024
1 parent 973690e commit 75783a8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Link from 'next/link'

import Stocks from '@/components/Stocks'
import Program from '@/components/Programs'

export default function Home() {
return (
<>
<Link prefetch={false} href={'/program/'} className="duration-200 block w-fit mt-5 mx-auto hover:text-custom-teal">
К программам
</Link>
<Stocks />
<Program />
</>
)
}
8 changes: 6 additions & 2 deletions src/app/program/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import {unstable_noStore as noStore} from 'next/cache'

import Link from 'next/link'
import Image from 'next/image'

import {client, urlForImage, urlForFile} from '@/lib/sanity'

const getData = async (slug) => {
noStore()

const query = `
*[_type == 'program' && slug.current == '${slug}'][0] {
name,
Expand All @@ -24,8 +28,8 @@ const ProgramPage = async ({params}) => {
return (
<section className="grid w-screen h-screen place-items-center">
<div className="flex flex-col items-center w-1/2 gap-5">
<Link href={'/'} className="mx-auto duration-200 w-fit hover:text-custom-teal">
На главную
<Link prefetch={false} href={'/program/'} className="duration-200 block w-fit mt-5 mx-auto hover:text-custom-teal">
К программам
</Link>
<div className="flex flex-col gap-5 p-5 border-2 border-custom-teal group">
<div className="flex gap-5">
Expand Down
14 changes: 14 additions & 0 deletions src/app/program/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Link from 'next/link'

import Programs from '@/components/Programs'

export default function Program() {
return (
<>
<Link prefetch={false} href={'/'} className="duration-200 block w-fit mt-5 mx-auto hover:text-custom-teal">
На главную
</Link>
<Programs />
</>
)
}
6 changes: 4 additions & 2 deletions src/components/Programs.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {unstable_noStore as noStore} from 'next/cache'

import Link from 'next/link'
import Image from 'next/image'
import {client, urlForImage} from '@/lib/sanity'
Expand All @@ -11,9 +13,9 @@ interface Program {
slug: {current: string}
}

export const revalidate = 30

const getData = async (): Promise<Program[]> => {
noStore()

const query = `
*[_type == 'program'] {
name,
Expand Down
4 changes: 4 additions & 0 deletions src/components/Stocks.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {unstable_noStore as noStore} from 'next/cache'

import Image from 'next/image'

import {client, urlForImage} from '@/lib/sanity'

const getData = async () => {
noStore()

const query = `
*[_type == 'stocks'] {
images
Expand Down

0 comments on commit 75783a8

Please sign in to comment.