-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simpler hook-only API without rendering a component? #1042
Comments
FWIW, you can do something similar already (with v9): import { Globals } from 'react-spring'
const { applyAnimatedValues } = Globals
const ref = useRef()
useSpring({
opacity: visible ? 1 : 0,
onChange(values) {
applyAnimatedValues(ref.current, values)
}
})
return <div ref={ref} /> You could make a custom hook to avoid duplication: function useAnimatedRef(props) {
const ref = useRef()
useSpring({
...props,
onChange(values) {
applyAnimatedValues(ref.current, values)
if (props.onChange) props.onChange(values)
}
})
return ref
}
const ref = useAnimatedRef({ opacity: visible ? 1 : 0 })
return <div ref={ref} /> edit: Oh wait, I forgot that |
Omg! That would be amazing! I'm guessing you meant |
I got it to work without |
My comment is only relevant to v9. For v8, everything is as you describe. 👍
Not sure. I'm not using v8 anymore. |
closing due to inactivity. please use discussions or discord if you want more help or please consider creating a PR if you want to add a feature 😄 |
Issue: 🚀 Feature Proposal
Thank you for this amazing animation library!
I've been wondering if there's any way for the animated component to be avoided at all by passing the ref directly to
useSpring(s)
. As far as I understand, the animated component is used only so that there is access to the ref (to directly set styles) and otherwise props are just passed down, but maybe I'm missing something here.Motivation
We'd like to create a hook that would contain
useSpring
that has access to the ref.Example
What I'm proposing would be this:
The text was updated successfully, but these errors were encountered: