mirror of
https://github.com/OwethuManagedServices/oms-website-nextjs.git
synced 2025-12-17 19:08:09 +00:00
feature: create post
This commit is contained in:
@ -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"
|
||||
|
||||
Reference in New Issue
Block a user