1

I have a react function that tries to live stream a bunch of mouse cursors for/to the people in the "room".

I'm updating/adding each mouse cursor with a web socket connection.

For some reason I can only get the animated react-spring element to show if I set a 'from'. It needs to be from the mouse's previous position and not from the corner / 0, 0 / fixed position.

const transitions = useTransition(mice, {
    enter: item => [
      { left: item.x, top: item.y },
    ],
    leave: item => [
      { left: item.x, top: item.y },
    ],
    delay: 0,
  })

  return (
    <>
    {transitions((props, item) => (
        <animated.div
          className='mouseCursor'
          key={item.id}
          style={props}>
        </animated.div>
      ))}
    </>
  )

Ashley Simons
  • 340
  • 4
  • 13

1 Answers1

0

This seems to have done the trick...

import { useTransition, animated, config } from 'react-spring';
// ...
const transitions = useTransition(mice, {
    config: { ...config.molasses, duration: 100 },
    from: {
      position: 'absolute', left: 0, top: 0,
    },
    enter: item => [
      { left: item.x, top: item.y },
    ],
    leave: item => [
      { left: item.x, top: item.y },
    ],
    update: item => [
      { left: item.x, top: item.y },
    ],
    keys: item => item.key,
    delay: 0,
  })
Ashley Simons
  • 340
  • 4
  • 13