Posts are same when you refresh page
Answered
Sun bear posted this in #help-forum
Sun bearOP
Hello, i Created this promtopia app from youtube video. but when i delete some post or create it seems main page is not changed
33 Replies
Sun bearOP
as you see profile page looks good
i have 3 post
but main page still shows 4
i will share main page code
"use client";
import Feed from "@/components/Feed";
const Home = () => {
return (
<section className="w-full flex-center flex-col">
<h1 className="head_text text-center">
Discover & Share
<br className="max-md:hidden" />
<span className="orange_gradient"> AI-Powered Prompts</span>
</h1>
<p className="desc text-center">
Promtopia is an open-source AI prompting tool for modern world to
Discover and Share AI prompts for creative writing.
</p>
{/* Feed */}
<Feed />
</section>
);
};
export default Home;
Tan
export const revalidate = 0
Answer
Tan
should fix it
Sun bearOP
@Tan
i will try
i added it to api and page
i didnot know if i needed something
because in video everything worked
import { connectToDB } from "@/utils/database";
import Prompt from "@/models/prompt";
export const revalidate = 0
export const GET = async (req, res) => {
try {
await connectToDB();
const prompts = await Prompt.find({}).populate("creator");
return new Response(JSON.stringify(prompts), {
status: 200,
});
} catch (error) {
return new Response("Error fetching prompts", {
status: 500,
});
}
};
this worked
but i still dont understand
why it worked?
when i use id or something like this it automatically revalidated data?
import { connectToDB } from "@/utils/database";
import Prompt from "@/models/prompt";
export const GET = async (req, { params }) => {
try {
await connectToDB();
const prompts = await Prompt.find({
creator: params.id,
}).populate("creator");
return new Response(JSON.stringify(prompts), {
status: 200,
});
} catch (error) {
return new Response("Error fetching prompts", {
status: 500,
});
}
};
like this
params.id
thanks
Does it update the posts when you click the browsers refresh button
Sun bearOP
yes @Alfonsus Ardani
now
i didnot know about this export things
i am new
but i like nextjs
@Sun bear but i like nextjs
Response are cached by default
By setting revalidate to 0 you disable caching
You can read the docs to know more about it, its in "Route Segment Config"
Sun bearOP
@Alfonsus Ardani thanks, i will read