feature: create post

This commit is contained in:
libertyoms
2025-04-22 08:50:55 +02:00
parent a8c6b5297b
commit 43f867cfe4
8 changed files with 518 additions and 12 deletions

View File

@ -20,10 +20,18 @@ export default function CreatePostForm() {
// Use useActionState from React
const [state, dispatch] = useActionState(createPost, initialState);
// Helper to get default value or empty string
// Helper to get default value or empty string, ensuring string return type
const getPreviousInput = (
key: keyof NonNullable<CreatePostState["previousInput"]>
) => state.previousInput?.[key] ?? "";
): string => {
const value = state.previousInput?.[key];
// Ensure the return value is always a string for text/textarea defaultValue
if (typeof value === "string") {
return value;
}
// Return empty string for non-string types (like boolean) or null/undefined
return "";
};
return (
// Remove encType="multipart/form-data"