react-utils - v1.0.31
    Preparing search index...
    • Custom hook for making POST requests with type safety and state management

      Type Parameters

      • T = User<Record<string, unknown>>

      Parameters

      • params: UsePostParams

        Configuration object for the request

        POST request parameters

        • path: string

          API endpoint path

        • Optionalbody?: object

          Optional request body

      Returns UsePostResult<T>

      An object containing:

      • data: The response data (type T) or null
      • error: Error message string or null
      • loading: Boolean indicating request status
      • sendPostRequest: Function to manually trigger the request
      // Basic usage with automatic execution
      const { data, loading } = usePost({
      path: 'users',
      body: { name: 'John' }
      });
      // Manual execution with custom type
      interface ApiResponse { id: string; status: string; }
      const { sendPostRequest } = usePost<ApiResponse>({
      path: 'orders'
      });
      // Error handling
      const { error } = usePost({
      path: 'login',
      body: credentials
      });
      useEffect(() => {
      if (error) showToast(error);
      }, [error]);
      • UsePostParams for parameter structure
      • UsePostResult for return type structure