pmndrs / react-spring

✌️ A spring physics based React animation library
http://www.react-spring.dev/
MIT License
28.22k stars 1.19k forks source link

[feat]: Better events for SpringValue. #2322

Open 1216892614 opened 1 month ago

1216892614 commented 1 month ago

A clear and concise description of what the feature is

const springV = useSpringValue(0);

springV.onChange((v) => console.log(`val now be ${v}`));

Just like a to function but always request value and return nothing. And same for other events.

Why should this feature be included?

It can help to share a SpringValue to others by pass in props. Now, I can only add listener at useSpringValue.

Please provide an example for how this would work

Im trying to pass a SpringValue called seed (witch computed by mousemove) to Subcomponents, and each Subcomponents owned a SpringValue called ans.

Normally ans should be computed by seed (like using to instead a useSpringValue). But when I drag a Subcomponent, it must return to oraginal status and folow my dragging.

So I can only use .set and .start in to function to set seed value to ans and put return on a fake animad.div.

1216892614 commented 1 month ago

How my animation look like

https://github.com/user-attachments/assets/93acf4c4-05d0-4c36-b629-88a554bd44de

1216892614 commented 1 month ago

And TBH, I use useSpringValue much much more than useSpring or others. I do think SpringValue should be the major hero feature, not useSpirng.