Axios fetcher(METHOD POST) + NextJs SSR = Infinite Endless API calls
See original GitHub issueUsing Method POST in Axios fetcher results in Endless API calls
Description / Observed Behavior
Using Method POST in Axios fetcher results in Endless API calls.
When using fetcher like
const fetcher = (url, data) => axios.post(url, data).then(res=>res.data)
const {data, error} = useSWR(['/api/v1/reports/statistics', data], fetcher)
Endless API calls. Infinite calling
But this happens only in SSR. And works fine with client Side rending.
Expected Behavior
Make only one API call during the server side rendering
Repro Steps / Code Example
const fetcher = (url, data) => axios.post(url, data).then(res=>res.data)
const StatisticsTable = ({criteria={}}) => {
const {data, error} = useSWR(['/api/v1/reports/statistics', criteria], fetcher)
return <div>{data}</div>
}
Additional Context
SWR version - 0.3.3 to 0.3.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Fetch data from Next.js API and create an infinite loading list ...
Check out https://screencasts.alterclass.io/ for more episodes!▻ Learn to build your own production-ready React applications and become a ...
Read more >Data Fetching: getServerSideProps - Next.js
Take the following example. An API route is used to fetch some data from a CMS. That API route is then called directly...
Read more >Getting infinite loop when making an axios get request
You need to put empty array (dependency) after the callback function: Change to: useEffect(() => { country = getCookie("title"); ...
Read more >Infinite Scroll React Example with TypeScript and NextJS
For the uninitiated, infinite scroll (otherwise known as endless scroll) refers to a method of automatically loading data when a user ...
Read more >Data fetching in Next.js — How To Use SWR - Ibrahima Ndaw
The fetcher function enables us to send the HTTP request to the server and then parse the response data to JSON. The fetch...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://swr.vercel.app/docs/arguments#passing-objects
Hope this will help
@vishnuvchandar I tried on your codesanbod example, the issue is when you pass an object to useSWR as first argument within next.js, each time the hashed key will be different
the weakmap in hash lib looks like following
the solution to this could be