How to get Fresh data with next.js and another backend api
Unanswered
fek posted this in #help-forum
fekOP
I'm using next.js 14 and I'm sending requests to the backend using another API. When I use fetch, if my page is not dynamic, that is, if I do not have a page like [id], [slug], my pages are created static and no fresh data comes. What can I do for it ?
20 Replies
@fek I'm using next.js 14 and I'm sending requests to the backend using another API. When I use fetch, if my page is not dynamic, that is, if I do not have a page like [id], [slug], my pages are created static and no fresh data comes. What can I do for it ?
fetch('https://...', { cache: 'no-store' })fekOP
Does this feature work on static pages?
@fek Does this feature work on static pages?
no, it will make the page become dynamic
if you want a static page, you will need to fetch the data on client side
fetch data from client side
@fek fetch data from client side
with client component
fekOP
useEffect ?
@fek useEffect ?
yes
const [data, setData] = useState([])
useEffect(() => {
fetch('https://...').then(res => res.json()).then(setData)
}, [])but its better to use react-query or swr for it
fekOP
hi @Ray
Frontend runs on localhost. Even though my data is still changing on the backend server, new data is not coming.
why is this happening
@fek Frontend runs on localhost. Even though my data is still changing on the backend server, new data is not coming.
what do you mean new data is not coming? do you see new data if you refresh the page?
fekOP
Actually, the post title named post 1 is not named post 1, I changed the name and still refreshed the same page many times, there were changes in my database and API, but there is no change in the frontend.
sometimes it loads 1 or 2 minutes late
I add, delete or update but the data still remains on the page
@fek I add, delete or update but the data still remains on the page
do you see the new data if you open
https://myapi/api/post/list on browser?