Skip to content

useAnimateStateChange

Animate an element when state value change.

Import

import {useAnimateStateChange} from '@kaiverse/k/hooks'

Usage

useAnimateStateChange hook animate an element when state value change.

The below displayed count element below will be flashed when you increment it:

Count value is 0

Type definition

function useAnimateStateChange<T extends HTMLElement = HTMLElement>({
ref,
value,
keyframes,
options,
triggerOnMount,
}: AnimateStateChangeHookOptions<T>): RefObject<T | null>

Special Types

NameTypeDescription
AnimateStateChangeHookOptionsSee useAnimateStateChange Options belowuseAnimateStateChange options.

useAnimateStateChange Options

NameTypeDefaultDescription
refReact.RefObject<T | null>Target element.
If you don’t wanna provide a ref, use this hook’s returned RefObject to attach to the element.
valueunknownThe animation will be triggered when this value changes.
If undefined or not provided, the animation will not be triggered.
Note: It uses Object.is to compare with the previous value.
triggerOnMountbooleanfalseWhether to trigger the animation when the component is mounted.
keyframesKeyframe[] | PropertyIndexedKeyframes | nullRequiredEither an array of keyframe objects, or a keyframe object whose properties are arrays of values to iterate over.
keyframes should be a constant. DO NOT change it at runtime, as the new one may not be applied.
Read more about Keyframe Formats.
optionsnumber | KeyframeAnimationOptionsEither an integer representing the animation’s duration (in milliseconds), or an Object containing one or more timing properties described in the KeyframeEffect() options parameter and/or other options.
options should be a constant. DO NOT update it, as the new options may not be applied.