Mirror: React hooks for accessible, common web interactions. UI super powers without the UI.

Simplify useStyleTransition animate function

Changed files
+4 -5
src
+4 -5
src/useStyleTransition.ts
···
return promise;
};
+
export type Animate = (options: TransitionOptions) => Promise<void> | void;
+
export function useStyleTransition<T extends HTMLElement>(
ref: Ref<T>,
options?: TransitionOptions
-
): [boolean, (options: TransitionOptions) => Promise<void>] {
+
): [boolean, Animate] {
if (!options) options = {};
const style = options.to || {};
···
};
const animation = animate(ref.current!, options);
+
updateAnimating(!!animation);
if (animation) {
-
updateAnimating(true);
return animation
.then(() => {
updateAnimating(false);
})
.catch(() => {});
-
} else {
-
updateAnimating(false);
-
return Promise.resolve();
}
},
[ref]