I create Next server actions while binding them (important) and I want to make this process simpler for me
This is what I initially had:
async function _signInUser(credentials: { login: string; password: string }) {
// some obscure and eerie manipulations 21+
return { credentials }
}
}
// actual function that I use in code (binding lets me use this func in client components)
export async function signInUser(credentials: { login: string; password: string }) {
return _signInUser.bind(null, credentials)()
}
I then removed the first declaration and used it anonymously (it worked):
export async function boundServerAction(_credentials: { login: string; password: string }) {
return (async (credentials: typeof _credentials) => {
// some obscure and eerie manipulations 21+
return { credentials }
}).bind(null, _credentials)()
}
Now I am spinning wheels in my brain trying to create a general purpose bindServerAction function that will get an async callback as the 1st param and return Promise of what this callback itself was supposed to return:
export const boundServerAction = bindServerAction(async (name: string) => { return name })
// boundServerAction: (name: string) => Promise<string>
Any ideas?
