#How do you export Server Actions from a ts file?

1 messages · Page 1 of 1 (latest)

silver heart
#

How do you export server actions from an external library?

This is my file structure:

lib/
     src/
               server-actions.ts
               index.ts
               custom-provider.tsx
playground
        (contains nextjs app)

How do i import the server-actions from lib to my nextjs playground ? It seems like normal import/export doesn't work for 'use server'.

tropic pierBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

silver heart
quiet flax
quiet flax
# silver heart wdym?

i'm just saying export the server code, like the main actions performed by that library (without nextjs specific stuff)

#

and re-export the rest in a actions.ts file in your nextjs app

silver heart
open idol
#

Server actions are meant to be used on the client, what do you mean?

frail wing
open idol
#

No I didn’t mean that, I said they’re meant to be used on the client not that they run on the client

frail wing
#

Ah my bad, I thought OP is concerned about server actions being leaked to the client

Which is true for exported functions

jovial geyser
frail wing
#

What do classes have to do with server functions?

silver heart
#

It seems like i can't use 'use server' directly in the files and bundle them. tsup doesn't allow this i think.

#

the next option would be to just export them as normal functions

#

but library users can use the functions in client components directly