Is there a cheaper option than useSWR built into Next? #4111
Unanswered
easy-thunder
asked this question in
Q&A
Replies: 1 comment
-
I read what you're asking as "Is there a cheaper option than polling my server once per second per user?" The answer to this is yes, there is a cheaper option and that option is to use some kind of data source you can listen for changes to rather than needing to poll the data source repeatedly. As to whether SWR has hooks that help with this, SWR has a hook that makes working with real-time data sources simple: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, so this is how I have implemented useSWR in the past:
const { data, error } = useSWR(gameIdRef.current ?
/api/games/connectFour?gameId=${gameIdRef.current}
: null, fetcher, {refreshInterval: 1000,
});
Basically polling my server every second for changes on a turn based game.
I did this for a school project and haven't deployed it because I'm worried that this might cause high costs if this game becomes popular. For example if I had an average of 10 players online all the time I estimate that would be 26 million requests a month.
I'm considering using PeerJS because most of what is paid is the initial handshake(or I believe please tell me if I'm wrong). But I'm pretty familiar and comfortable with Next.js and am curious if there are other options that could reduce cost.
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions