next-cool-action
Recipes

i18n

Learn how to use next-cool-action with a i18n solution.

i18n

If you're using a i18n solution, there's a high probability that you'll need to await the translations and then pass them to schemas. next-cool-action allows you to do that by passing an async function to the schema method that returns a promise with the schema. The setup is pretty simple:

"use server";

import { actionClient } from "@/lib/cool-action";
import { z } from "zod";
import { getTranslations } from "my-i18n-lib";

async function getSchema() {
  // This is an example of a i18n setup.
  const t = await getTranslations();
  return mySchema(t); // this is the schema that will be used to validate and parse the input
}

export const myAction = actionClient
  .inputSchema(getSchema)
  .action(async ({ parsedInput }) => {
  // Do something useful here...
});

On this page