useMotion
useMotion is the primitive behind every motion.* component. It returns a getter that merges
regular element props with motion props, plus a <Provider> for variant propagation. Use it when a
Solid component owns its own ref or needs to compose motion behavior manually.
import { useMotion } from 'motion-solidjs'
function Panel(props: { open: boolean }) {
const m = useMotion(() => ({
initial: { opacity: 0 },
animate: { opacity: props.open ? 1 : 0 },
transition: { duration: 0.2 },
}))
return (
<m.Provider>
<div {...m({ class: 'panel' })} />
</m.Provider>
)
}
API
useMotion(props)-propsis a function returning a reactive motion-props object- Returns
m- call it with regular element props to receive merged props m.Provider- variant context provider; render it once peruseMotioninstance
See also
motion- the component built on top of this primitive