Next.js Discord

Discord Forum

Polymorphic custom util functions?

Unanswered
Kawakawa posted this in #help-forum
Open in Discord
Original message was deleted.

10 Replies

hmm try moving the functions to different files; so server component util functions are not in the same file as the client component util functions
However this might be an issue
I put the util function in there, and it is calculated dynamically on every request.
However, that means I would have to use both "util functions" - but then surely that wouldn't work as they'd both be imported into the client.ts file (for the graphql-request client) but one would be a client thing and one would be a server thing?
Could I possibly use dynamic imports? Or would that be a little bad performance wise/for any other reason?
i don't use graphql so i don't know about this
@joulev i don't use graphql so i don't know about this
Kawakawa
Well it's hardly gql specific - I'm just wondering if I can write one util function, and have it dynamic import either the next cookies function or js-cookies based on if it's being ran on the server?