Function useMethod

  • Hook for making dynamically update or query calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.

    Type Parameters

    Returns UseMethodReturnType<A, M>

    object UseMethodReturnType.

    Example

    function MethodCallComponent() {
    const { call, data, loading } = useMethod({
    functionName: 'updateUserProfile',
    args: ['123', { name: 'John Doe' }],
    onLoading: (loading) => console.log('Loading:', loading),
    onError: (error) => console.error('Error:', error),
    onSuccess: (data) => console.log('Success:', data),
    });

    if (loading) return <p>Updating profile...</p>;

    return (
    <div>
    <p>Updated Profile: {JSON.stringify(data)}</p>
    <button onClick={call}>Update</button>
    </div>
    );
    }