|
Download react-use/docs/useSpring.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 850 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useSpring.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useSpring.md
-
curl -L -o useSpring.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useSpring.md
850 Bytes
| # `useSpring` | |
| React animation hook that updates a single numeric value over time according | |
| to spring dynamics. | |
| ## Usage | |
| ```jsx | |
| import useSpring from 'react-use/lib/useSpring'; | |
| const Demo = () => { | |
| const [target, setTarget] = 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> | |
| ); | |
| }; | |
| ``` | |
| Note: Because of dependency on `rebound` you have to import this hook directly like shown above. | |
| ## Requirements | |
| Install [`rebound`](https://github.com/facebook/rebound-js) peer dependency: | |
| ```bash | |
| npm add rebound | |
| # or | |
| yarn add rebound | |
| ``` | |
| ## Reference | |
| ```js | |
| const currentValue = useSpring(targetValue); | |
| const currentValue = useSpring(targetValue, tension, friction); | |
| ``` | |