ベースマキナ ドキュメント

useExecuteActionLazy

useExecuteActionLazyはアクションの実行を遅延させるためのフックです。このフックはアクションの識別子を引数として受け取り、そのアクションの実行を開始する関数とアクションの実行状態を返します。

基本的な使い方

const App = () => {
    const [execute, { data, loading, error }] = useExecuteActionLazy("action-id");
    
    const handleClick = () => {
        execute([{
            name: "param1",
            value: "value1"
        }, {
            name: "param2",
            value: "value2"
        }]);
    }

    return (
        <div>
            <button onClick={handleClick}>Execute Action</button>
            {loading && <LoadingIndicator />}
            {data && <Table rows={data.results[0].success ?? []}/>}
        </div>
    )
}

詳細なインターフェース

引数

識別子説明
actionId文字列実行するアクションのID。アクションは、アプリケーションの特定の機能を実行するための識別子です。c3hc2ii23akg0sokf9j0

戻り値

プロパティ名説明
execute関数引数としてアクションのパラメータを受け取り、アクションを実行する関数。-
stateオブジェクトアクションの実行状態を表すオブジェクト。このオブジェクトはloadingdataerrorの3つのプロパティを持ちます。-
state.loadingbooleanアクションが現在実行中かどうかを示すブール値。true
state.dataオブジェクトアクションの実行結果。このオブジェクトはresultsという名前の配列を持っておりsuccessfailure のプロパティが含まれます。{"results":[{"success":[{"id":1,"name":"山田太郎"}]}]}
state.errorオブジェクトアクションの実行中に発生したエラー。-