To pass data from a child function to a parent function using the action attribute in Server Actions next.js 14

This is a very simplified version. But the essence of the problem is that, during the form check, if the field is not filled in, I want to display
error text over the input. And to do this, I need to get the error text from the catch (error) function CreateTitle to the parent
function FormErrorAction to then pass this text to < p > </p >. And also I need to get id from CreateTitle.
` const FormErrorAction = () => {

error = " data obtained from the function CreateTitle "

async function CreateTitle(data: FormData) {
"use server"
try {
const { title} = Object.fromEntries(data);

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if (typeof title !== "string" || title.includes(" ") || title.length < 0) {
throw new Error("Fill in the field title");
} text = "Registration was successful";
const formId = new ObjectId().toString();
const array = JSON.stringify({ title, id: formId, });
await Create(array);
return formId
</code>
<code>if (typeof title !== "string" || title.includes(" ") || title.length < 0) { throw new Error("Fill in the field title"); } text = "Registration was successful"; const formId = new ObjectId().toString(); const array = JSON.stringify({ title, id: formId, }); await Create(array); return formId </code>
if (typeof title !== "string" || title.includes(" ") || title.length < 0) {
  throw new Error("Fill in the field title");
}  text = "Registration was successful";

const formId = new ObjectId().toString();
const array = JSON.stringify({ title, id: formId, });

await Create(array);
return formId

} catch (error) {
return error;
}
revalidatePath(/errorServerAction);
}

return (
<div>
<form
action={CreateTitle}

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> >
{
error && <p >{error}</p>
}
<label htmlFor="todo"> Fill in the field</label>
<input
type="text"
id="todo"
placeholder="title"
required
name="title"
/>
<button type="submit" value="Add post">
to begin
</button>
</form>
</div>
</code>
<code> > { error && <p >{error}</p> } <label htmlFor="todo"> Fill in the field</label> <input type="text" id="todo" placeholder="title" required name="title" /> <button type="submit" value="Add post"> to begin </button> </form> </div> </code>
     >
        {
             error && <p >{error}</p>
        }
            <label htmlFor="todo"> Fill in the field</label>
            <input
                 type="text"
                  id="todo"
                  placeholder="title"
                 required
                 name="title"
             />

        <button type="submit" value="Add post">
              to begin
        </button>

  </form>
</div>

);
};

export default FormErrorAction;`

I tried to put the CreateTitle form handler function into a separate server file,
and make the function itself a client component. In the FormErrorAction function, create the clientAction function,
which should receive data from CreateTitle, check and transfer the received data to the useState hook ()
to then display the error. But I faced a new problem. So that the browser does not reload the form
event.preventDefault () is needed, and the action attribute only works with data: FormData. I also tried to get data using collback,
but the result`
"use server"
export async function CreateTitle(data: FormData) {
try {
const { title} = Object.fromEntries(data);

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if (typeof title !== "string" || title.includes(" ") || title.length < 0) {
throw new Error("Fill in the field title");
} text = "Registration was successful";
const formId = new ObjectId().toString();
const array = JSON.stringify({ title, id: formId, });
await Create(array);
return formId
</code>
<code>if (typeof title !== "string" || title.includes(" ") || title.length < 0) { throw new Error("Fill in the field title"); } text = "Registration was successful"; const formId = new ObjectId().toString(); const array = JSON.stringify({ title, id: formId, }); await Create(array); return formId </code>
if (typeof title !== "string" || title.includes(" ") || title.length < 0) {
  throw new Error("Fill in the field title");
}  text = "Registration was successful";

const formId = new ObjectId().toString();
const array = JSON.stringify({ title, id: formId, });

await Create(array);
return formId

} catch (error) {
return error;
}
revalidatePath(/errorServerAction);
}
"use client"
const FormErrorAction = () => {
const [error, setError] = useState("");
const errorRef = useRef<HTMLFormElement>(null);

error = " data obtained from the function CreateTitle "

async function clientAction(data: FormData) {
const result = await CreateTitle(data);

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> if (typeof result === "string") {
const id = result;
await RevalidatePath();
} else {
if (result?.error) {
setError(result.error);
} else {
errorRef.current?.reset();
await RevalidatePath();
setError("Registration succeeded ");
}
}
</code>
<code> if (typeof result === "string") { const id = result; await RevalidatePath(); } else { if (result?.error) { setError(result.error); } else { errorRef.current?.reset(); await RevalidatePath(); setError("Registration succeeded "); } } </code>
   if (typeof result === "string") {
  const id = result;
       await RevalidatePath();
} else {
     if (result?.error) {
      setError(result.error);
  } else {
    errorRef.current?.reset();
    await RevalidatePath();
   setError("Registration succeeded ");

  }
}

}

return (
<div>
<form
action={clientAction}
ref={errorRef}
>
{
error && <p >{error}</p>
}
<label htmlFor="todo"> Fill in the field</label>
<input
type="text"
id="todo"
placeholder="title"
required
name="title"
/>

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <button type="submit" value="Add post">
to begin
</button>
</form>
</div>
</code>
<code> <button type="submit" value="Add post"> to begin </button> </form> </div> </code>
        <button type="submit" value="Add post">
              to begin
        </button>

  </form>
</div>

);
};

export default FormErrorAction;

` is the same.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật