当我单击该组件时,所有组件都会重新呈现数据。
我的页面.jsx
const Home = () => {
return(
<RefreshBtn />
<Suspense fallback={<NoteSkeleton />}>
<Feed />
</Suspense>
)
}
export default Home
字符串
RefreshBtn组件
'use client'
import { useRouter } from 'next/navigation'
async function RefreshBtn () {
const router = useRouter();
const handleBtn = async (e) => {
router.refresh();
}
return (
<button onClick={handleBtn}>
Refresh
</button>
);
};
export default RefreshBtn;
型
馈电元件SSR
import PromptCard from './PromptCard';
// use to fetch data from api
async function fetchPosts() {
try{
const response = await fetch('http://localhost:3000/api/prompt', { cache: 'no-store' });
const data = await response.json();
const posts = data;
return posts;
} catch(error) {
console.log(error);
}
}
// render the Feed component
async function Feed() {
const posts = await fetchPosts();
console.log(posts);
return (
<div className='mt-16 prompt_layout'>
{posts.map((post) => (
<PromptCard
key={post._id}
post={post}
/>
))}
</div>
);
}
export default Feed;
型
我想显示回退,但如果单击RefreshBtn,它会更新数据并重新获取所有内容,但不显示回退
1条答案
按热度按时间owfi6suc1#
我发现的一个解决方法是有一个在刷新时更改的键,以便Next知道内容已经更改:
Home.jsx
字符串