Replies: 4 comments 3 replies
-
Technically it should be possible to use it with any HTTP method, what method you use in your fetcher is not a concern of SWR, however usually POST modified somehow the data server side (eg creating a new resource) so it’s bette to use GET, if you know your API ask you to use POST to read data you can use it, just be aware that SWR may call your fetcher function again anytime and that could have side effects if your API call is not idempotent. |
Beta Was this translation helpful? Give feedback.
-
You can adjust your fetcher like so:
Now it accepts payload, when there is payload it assumes you want to POST it. Make sure payload is not an object else it will recreate new one and continue posting :) Example usage:
Like Sergio is mentioning its only meant to use where your method needs to be a post but actually is about retrieving data. |
Beta Was this translation helpful? Give feedback.
-
We have this PR working in progress: #1450, please take a look and any feedback is welcome! |
Beta Was this translation helpful? Give feedback.
-
its for showing where to set typescript generic |
Beta Was this translation helpful? Give feedback.
-
hi guys,
Im confused,
Is swr hook only work with get Method?
I've tried alot to get data with post method in swr , but i coulnt ,
Im using next js , i get data in getiinitialprops(with post method) and pass it to initialData,
It doesnt work when i change the routes ... how can we use it with post method to cache api?
Beta Was this translation helpful? Give feedback.
All reactions