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

How to use with props? #6

Open
geohuz opened this issue Aug 30, 2023 · 0 comments
Open

How to use with props? #6

geohuz opened this issue Aug 30, 2023 · 0 comments

Comments

@geohuz
Copy link

geohuz commented Aug 30, 2023

The examples are all using const value, I'm not sure how to use it with props value? , eg:

const springs = createSpring({
   from: { x: props.x, y: props.y}
...

But then the animted.div doesn't get react anyway, any solution for this issue?

And here is my code snippet for using spring to show an dot animation on positions (passed by props.x, props.y):

function Dot(props) {
  const [local] = splitProps(props, ["x", "y"])

  const styles = createSpring({
    from: {
      x: local.x,
      y: local.y 
    },
    to: {
      x: local.x,
      y: local.y
    }
  })


  
  return (
    <>
      <animated.div
        style={{
          width: `20px`,
          height: `20px`,
          background: '#ff6d6d',
          "border-radius": '50%',
          ...styles()
        }}
      >
        <span>RID:{Math.random()}</span>
      </animated.div> 
    
    </>
  )
}

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

No branches or pull requests

1 participant