Skip to content
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

[FEATURE] onUpdate return a new computed state #220

Closed
samdenty opened this issue Jul 20, 2019 · 1 comment
Closed

[FEATURE] onUpdate return a new computed state #220

samdenty opened this issue Jul 20, 2019 · 1 comment
Labels
feature New feature or request

Comments

@samdenty
Copy link

samdenty commented Jul 20, 2019

Is your feature request related to a problem? Please describe.

Ability to return a new animation state for each frame, inside onUpdate.

Describe the solution you'd like

const Component = props => (
  <motion.div
    {...props}
    onUpdate={state => ({ opacity: computeOpacity(state.rotateX), ...state })}
  />
)

const Test = () => (
  <Component initial={{ rotateX: 0 }} animate={{ rotateX: 90 }} />
)

Describe alternatives you've considered

Passing motionValues to a component via props instead. But using motionValues means you miss out on using variants, whileHover etc.

const Component = ({ rotateX }) => {
  const opacity = useTransform(rotateX, computeOpacity)

  return <motion.div style={{ opacity, rotateX }} />
}

const Test = () => {
  const rotateX = useSpring(0)
  useEffect(() => {
    setTimeout(() => rotateX.set(90), 50)
  }, [])
  
  return <Component rotateX={rotateX} />
}
@samdenty samdenty added the feature New feature or request label Jul 20, 2019
@mattgperry
Copy link
Collaborator

mattgperry commented Jul 22, 2019

Hi @samdenty. Have you got an example of a specific use-case of something you're currently unable to achieve because of MotionValues? Even though you define a prop using a MotionValue you are still able to use variants, whileHover etc to animate them. The MotionValue is just there to create relationships.

const Component = ({ animate, rotateX }) => {
  const rotateX = useMotionValue(0)
  const opacity = useTransform(rotateX, computeOpacity)

  return <motion.div animate={{ rotateX: 90 }} style={{ opacity, rotateX }} />
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants