File size: 2,752 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
meta:
  title: useSpringValue | React Spring
  'og:title': useSpringValue | React Spring
  'twitter:title': useSpringValue | React Spring
  description: API documentation for the useSpringValue hook in React Spring.
  'og:description': API documentation for the useSpringValue hook in React Spring.
  'twitter:description': API documentation for the useSpringValue hook in React Spring.
  'og:url': https://www.react-spring.dev/docs/components/use-spring-value
  'twitter:url': https://www.react-spring.dev/docs/components/use-spring-value
sidebar_position: 3
isNew: true
---

import { formatFrontmatterToRemixMeta } from '../helpers/meta'

export const meta = formatFrontmatterToRemixMeta(frontmatter)

# useSpringValue

Love the imperative API but you need _too many_ different springs running in parallel? Then this
hook is for you! It's a simple wrapper around a [`SpringValue`](/docs/components/spring-value) and
therefore behaves the same, so you can access it's methods imperatively.

## Usage

### Value only

```tsx
import { useSpringValue, animated } from '@react-spring/web'

function MyComponent() {
  const opacity = useSpringValue(0)

  return <animated.div style={{ opacity }}>Hello World</animated.div>
}
```

### With configuration

```tsx
import { useSpringValue, animated } from '@react-spring/web'

function MyComponent() {
  const opacity = useSpringValue(0, {
    config: {
      mass: 2,
      friction: 5,
      tension: 80,
    },
  })

  return <animated.div style={{ opacity }}>Hello World</animated.div>
}
```

## Updating

:::warning
Unlike our other hooks, this one **will not** react to updates in the component. This is by design.
You **must** use the methods on the returned `SpringValue` to update said value.
:::

```tsx
import { useSpringValue, animated } from '@react-spring/web'

function MyComponent() {
  const opacity = useSpringValue(0, {
    config: {
      mass: 2,
      friction: 5,
      tension: 80,
    },
  })

  const handleClick = () => opacity.start(1)

  return (
    <animated.div onClick={handleClick} style={{ opacity }}>
      Hello World
    </animated.div>
  )
}
```

## Reference

import { TablesConfiguration } from '../components/Tables/TablesConfig'
import { USESPRINGVALUE_CONFIG_DATA } from '../data/fixtures'

<TablesConfiguration data={USESPRINGVALUE_CONFIG_DATA} />

## Typescript

```tsx
function useSpringValue<T>(value: T): SpringValue<T>

function useSpringValue<T>(value: T, config: ConfigObject): SpringValue<T>
```

Where `ConfigObject` is described [above](#reference)

## Examples

import { ExampleGrid } from '../components/Grids/ExampleGrid'

<ExampleGrid sandboxTitles={['MacOS Dock']} />

Can't find what you're looking for? Check out all our [examples!](/examples)