logo
kaimul
my 7th Blog

my 7th Blog

shareshareshareshare
kaimul
By Kaimul alam
0 mins to read

my 7th Blog

jsx

import { createTodoAction } from "@/app/_action";

export default function TodoForm() {
  async function action(data: FormData) {
    "use server";

    const title = data.get("title");
    if (!title || typeof title !== "string") {
      return;
    }

    // Invoke server action to add new todo
    await createTodoAction({ title, path: "/" });
  }

  return (
    <form
      action={action}
      key={Math.random()}
      className="flex items-center space-x-2 mb-4"
    >
      <input
        type="text"
        name="title"
        className="border rounded px-2 py-1 flex-1"
      />
      <button className="px-4 py-1 text-white rounded bg-green-500">Add</button>
    </form>
  );
}

Comments

    leave a comment

    related blogs

    post

    my 10th blog

    0 mins to read
    post

    my 7th Blog

    0 mins to read
    post

    my 7th Blog

    0 mins to read

    categories

    icon

    Others

    (8)
    icon

    Featured

    (5)
    icon

    React

    (4)
    icon

    Scss

    (3)
    icon

    Css

    (3)
    icon

    next

    (3)
    icon

    Sanity

    (2)
    icon

    slider

    (1)
    icon

    Tailwind

    (0)
    icon

    MongoDB

    (0)