Documentation Index Fetch the complete documentation index at: https://mintlify.com/anupom69/bun-hono-frontend-nextjs/llms.txt
Use this file to discover all available pages before exploring further.
Function Signature
async function deleteMessage (
prevState : MessagePrevState ,
formData : FormData
) : Promise < MessagePrevState >
Source: src/lib/actions/message/deleteMessage.ts:9
Parameters
Previous state object returned from the last invocation. Used by React’s useActionState hook. Indicates if the previous operation was successful
Error message from the previous operation
Form data containing the message identifier The unique identifier of the message to delete Validation:
Must be present (non-null, non-empty)
Error: “ID is required”
Return Value
Set to true when the message is deleted successfully
Set to false when an error occurs
Error message describing what went wrong Possible errors:
“ID is required” - No ID provided in form data
“Backend Error: ” - Backend API error
Error message or “Something went wrong” - Network or unexpected errors
Validation
This function performs simple validation without Zod:
const id = formData . get ( "id" );
if ( ! id ) {
return {
success: false ,
error: "ID is required" ,
};
}
Behavior
Validation : Checks that the ID field is present
API Call : Makes a POST request to {BACKEND_URL}/messages/delete-one/{id}
Authentication : Uses Basic Auth with environment credentials
Revalidation : Calls revalidatePath("/") on success to refresh the home page
Error Handling : Returns structured error messages with success: false flag
Usage Example
import { useActionState } from "react" ;
import deleteMessage from "@/lib/actions/message/deleteMessage" ;
function DeleteMessageButton ({ messageId } : { messageId : string }) {
const [ state , formAction ] = useActionState ( deleteMessage , {});
return (
< form action = { formAction } >
< input type = "hidden" name = "id" value = { messageId } />
< button type = "submit" > Delete Message </ button >
{ state . error && < p >{ state . error }</ p >}
{ state . success && < p > Message deleted !</ p >}
</ form >
);
}
function MessageList ({ messages }) {
const handleDelete = async ( messageId : string ) => {
const formData = new FormData ();
formData . set ( "id" , messageId );
const result = await deleteMessage ({}, formData );
if ( result . success ) {
console . log ( "Message deleted" );
} else {
console . error ( result . error );
}
};
return (
< ul >
{ messages . map (( msg ) => (
< li key = {msg. id } >
{ msg . content }
< button onClick = {() => handleDelete (msg.id)} > Delete </ button >
</ li >
))}
</ ul >
);
}
Backend Endpoint
POST /messages/delete-one/:id
Headers:
Authorization: Basic authentication
Body: None (ID is in the URL path)
Note on Error Responses
Unlike createMessage and updateMessage, this function explicitly sets success: false in error responses, making it easier to check the operation status without relying solely on the presence of an error message.