Это сильно упрощёный вариант. Но суть проблемы в том что, мне надо получить текст ошибки из catch (error) и id из функции CreateTitle
в родительскую функцию FormErrorAction
const FormErrorAction = () => {
error = " полученные данные из функции CreateTitle "
async function CreateTitle(data: FormData) {
"use server"
try {
const { title} = Object.fromEntries(data);
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}
>
{
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;