mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
@daml/react: Add proper useExerciseByKey hook (#4368)
And remove the old quirky `usePseudoExerciseByKey` hook. CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
4d7e62de1f
commit
782f7e61d8
@ -112,20 +112,20 @@ export const useExercise = <T extends object, C, R>(choice: Choice<T, C, R>): [(
|
||||
return [exercise, loading];
|
||||
}
|
||||
|
||||
/// React Hook that returns a function to exercise a choice and a boolean
|
||||
/// React Hook that returns a function to exercise a choice by key and a boolean
|
||||
/// indicator whether the exercise is currently running.
|
||||
export const usePseudoExerciseByKey = <T extends object, C, R>(choice: Choice<T, C, R>): [(key: Query<T>, argument: C) => Promise<R>, boolean] => {
|
||||
export const useExerciseByKey = <T extends object, C, R, K>(choice: Choice<T, C, R, K>): [(key: K, argument: C) => Promise<R>, boolean] => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const state = useDamlState();
|
||||
|
||||
const exercise = async (key: Query<T>, argument: C) => {
|
||||
const exerciseByKey = async (key: K, argument: C) => {
|
||||
setLoading(true);
|
||||
const [result, events] = await state.ledger.exerciseByKey(choice, key, argument);
|
||||
state.dispatch(addEvents(events));
|
||||
setLoading(false);
|
||||
return result;
|
||||
}
|
||||
return [exercise, loading];
|
||||
return [exerciseByKey, loading];
|
||||
}
|
||||
|
||||
/// React Hook to reload all queries currently present in the store.
|
||||
|
Loading…
Reference in New Issue
Block a user