mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
35 lines
611 B
Markdown
35 lines
611 B
Markdown
# `useSpring`
|
|
|
|
React animation hook that updates a single numeric value over time according
|
|
to spring dynamics.
|
|
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
import {useSpring} from 'react-use';
|
|
|
|
const Demo = () => {
|
|
const [target, setTarget] = (React as any).useState(50);
|
|
const value = useSpring(target);
|
|
|
|
return (
|
|
<div>
|
|
{value}
|
|
<br />
|
|
<button onClick={() => setTarget(0)}>Set 0</button>
|
|
<button onClick={() => setTarget(100)}>Set 100</button>
|
|
</div>
|
|
);
|
|
};
|
|
```
|
|
|
|
|
|
# Reference
|
|
|
|
|
|
```js
|
|
const currentValue = useSprgin(targetValue);
|
|
const currentValue = useSprgin(targetValue, tension, friction);
|
|
```
|