useAnimate | Framer for Developers
useAnimate provides a way of using the animate function that is scoped to the elements within your component. It provides a scope ref, and an animate function where every DOM selector is scoped to this ref. Additionally, when the component calling useAnimate is removed, all animations started with its returned animate function will be cleaned up automatically. Declarative animations via motion components tend to be simpler to write and maintain. However, imperative animations via useAnimate() are very powerful, allowing: Ultimately which you use depends on your needs and usecase. Import from "framer-motion". useAnimate returns two arguments, a scope ref and an animate function. This scope ref must be passed to either a regular HTML/SVG element or a motion component. This scoped animate function can now be used in effects and event handlers to animate elements. We can either use the scoped element directly: Or by passing it a selector. This selector is "li", but we're not selecting all
useAnimate provides a way of using the animate function that is scoped to the elements within your component. This allows you to use manual animation controls, timelines, selectors scoped to your component, and automatic cleanup. It provides a scope ref, and an animate function where every DOM selector is scoped to this ref. function Component () { const [ scope , animate ] = useAnimate () useEffect (() => { // This "li" selector will only select children // of the element that receives `scope`. animate ( " li " , { opacity : 1 }) }) return < ul ref = { scope } > { children } </ ul > } Additio
related reading
- Motion (prev Framer Motion): JavaScript & React animation librarymotion.dev
- AnimatePresence | React exit animationsmotion.dev
- animations.devanimations.dev
- You Might Not Need an Effect – Reactreact.dev
- Anime.js | JavaScript Animation Engineanimejs.com
- Animated Elements | React Springreact-spring.dev
- Inside Framer's Magic Motionnan.fyi
- Reduce bundle size of Framer Motion | Motion for Reactmotion.dev
- Understanding useMemo and useCallback • Josh W. Comeaujoshwcomeau.com
- propEffect | Render motion values to object props | Motionmotion.dev
- The Power of Keys in Framer Motionnan.fyi
- React useRef Hook By Example: A Complete Guidelearnreact.design