Download react-spring/packages/core/src/hooks/useSpringValue.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 931 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/core/src/hooks/useSpringValue.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/core/src/hooks/useSpringValue.ts
-
curl -L -o useSpringValue.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/core/src/hooks/useSpringValue.ts
931 Bytes
| import { useConstant, useOnce } from '@react-spring/shared' | |
| import { SpringValue } from '../SpringValue' | |
| import { SpringUpdate } from '../types' | |
| /** | |
| * Creates a constant single `SpringValue` that can be interacted | |
| * with imperatively. This is an advanced API and does not react | |
| * to updates from the parent component e.g. passing a new initial value | |
| * | |
| * | |
| * ```jsx | |
| * export const MyComponent = () => { | |
| * const opacity = useSpringValue(1) | |
| * | |
| * return <animated.div style={{ opacity }} /> | |
| * } | |
| * ``` | |
| * | |
| * @param initial – The initial value of the `SpringValue`. | |
| * @param props – Typically the same props as `useSpring` e.g. `config`, `loop` etc. | |
| * | |
| * @public | |
| */ | |
| export const useSpringValue = <T>( | |
| initial: Exclude<T, object>, | |
| props?: SpringUpdate<T> | |
| ) => { | |
| const springValue = useConstant(() => new SpringValue(initial, props)) | |
| useOnce(() => () => { | |
| springValue.stop() | |
| }) | |
| return springValue | |
| } | |