useFyskAnimation Hook
The centralized animation control system for Fysk. Provides pre-computed transitions and variants for consistent, professional animations across all components.
About useFyskAnimation
The useFyskAnimation hook is the bridge between your animation configuration (set in FyskProvider) and individual components. It provides:
Motion Access: Returns the framer-motion
motionobject or fallback HTML elements when animations are disabled.Pre-computed Transitions: Ready-to-use transition objects based on your duration and easing configuration.
Pre-computed Variants: Animation variants (fadeSlide, iconPop, scaleIn, etc.) that respect your effects configuration.
Conditional Logic: Automatically handles the enabled/disabled state so components gracefully degrade.
Why Centralized Animations?
Without centralization, animation values are scattered across components—a 200ms here, an easeOut there. This leads to:
Inconsistency: Different components feel disconnected because of varying timings.
Maintenance Pain: Changing the "feel" of your app requires editing dozens of files.
Bundle Bloat: framer-motion is imported everywhere, even when animations might be disabled.
The useFyskAnimation hook solves all of these by:
Single Source of Truth: All timing and easing values come from one configuration.
Instant Global Updates: Tweak
durations.normalonce, and every component updates.Tree-Shakeable: When
enabled: false, framer-motion is never imported by components.
Usage
Import the hook and destructure what you need:
Return Values
The hook returns an object with everything you need for animations:
Transitions
Pre-computed transition objects based on your configuration. Each is optimized for its specific use case:
Variants
Pre-computed animation variants that respect your effects configuration:
Configuration
Animation behavior is configured through FyskProvider. The hook reads this configuration and computes transitions/variants accordingly:
All values have sensible defaults based on The Easing Blueprint, so you can start with just { enabled: true, motion, AnimatePresence }.
Example: Custom Component
Here's how to build a custom animated component using the hook:
This component will animate smoothly when animations are enabled, and fall back to instant state changes when disabled—no extra code required.
Built with 💖 | Created by Yashraj