Skip to content

Commit 29cc03b

Browse files
committed
fix examples, amend docs, add useSprings section
1 parent a6d1e5b commit 29cc03b

File tree

6 files changed

+58
-15
lines changed

6 files changed

+58
-15
lines changed

.size-snapshot.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@
8080
}
8181
},
8282
"dist/hooks.js": {
83-
"bundled": 80723,
84-
"minified": 38373,
85-
"gzipped": 12424,
83+
"bundled": 80699,
84+
"minified": 38363,
85+
"gzipped": 12434,
8686
"treeshaked": {
8787
"rollup": {
8888
"code": 16403,
8989
"import_statements": 341
9090
},
9191
"webpack": {
92-
"code": 28886
92+
"code": 28881
9393
}
9494
}
9595
},
@@ -99,16 +99,16 @@
9999
"gzipped": 12303
100100
},
101101
"dist/native-hooks.js": {
102-
"bundled": 72460,
103-
"minified": 34159,
104-
"gzipped": 10586,
102+
"bundled": 72436,
103+
"minified": 34149,
104+
"gzipped": 10591,
105105
"treeshaked": {
106106
"rollup": {
107107
"code": 10006,
108108
"import_statements": 345
109109
},
110110
"webpack": {
111-
"code": 25046
111+
"code": 25041
112112
}
113113
}
114114
}

documentation/Hooks.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,50 @@ return items.map((item, index) => (
144144
))}
145145
</DemoGrid>
146146
147+
## useSprings
148+
149+
`useSprings(Count, [Values] | index => Values): [animatedProps] | [[animatedProps], set]`
150+
151+
<p>
152+
useSprings has a similar api as useTrail, the only distinction is that the springs don't trail, you define individual values for them.
153+
</p>
154+
155+
<h3>
156+
<span className="highlight"><i>Either</i>: overwrite values</span> to change the animation
157+
</h3>
158+
159+
```jsx
160+
const props = useSprings(items.length, [{ x: 0 }, { x: 1000 }, { x: 2000 }] })
161+
```
162+
163+
<h3>
164+
<span className="highlight"><i>Or</i>: pass a function</span> that returns values, and update using "set"
165+
</h3>
166+
167+
```jsx
168+
const [props, set] = useSprings(items.length, index => ({ x: index * 1000 } }))
169+
```
170+
171+
<h3>
172+
<span className="highlight"><i>Finally</i>: distribute animated props</span> among the view
173+
</h3>
174+
175+
```jsx
176+
return items.map((item, index) => (
177+
<animated.div key={item.key} style={props[index]}>{item.content}</animated.div>
178+
)
179+
```
180+
181+
<DemoGrid padding={0}>
182+
{examples.filter(data => data.tags.includes('useSprings')).map(data => (
183+
<Demo
184+
key={data.name}
185+
{...data}
186+
import={import('../examples/demos/' + data.name)}
187+
/>
188+
))}
189+
</DemoGrid>
190+
147191
## useTransition
148192
149193
`useTransition(Config): [{ item, key, props, state }]`

examples/components/examples-hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ return <animated.div style={{ transform }} children="Slide">`,
7272
name: 'hooks/draggable-list',
7373
title: 'Draggable list',
7474
link: 'https://codesandbox.io/embed/r5qmj8m6lq',
75-
tags: ['useTrail'],
75+
tags: ['useSprings'],
7676
},
7777
{
7878
name: 'hooks/mouse-parallax',

examples/demos/hooks/keyframes-script/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useEffect } from 'react'
22
import { useKeyframes, animated } from 'react-spring/hooks'
33
import './styles.css'
4-
import { useChain } from '../../../../dist/hooks'
54

65
const useScript = useKeyframes.spring(async next => {
76
while (true) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"react-testing-library": "5.2.0",
105105
"react-transition-group": "2.5.0",
106106
"react-twitter-widgets": "1.7.1",
107-
"react-with-gesture": "2.0.4",
107+
"react-with-gesture": "4.0.0",
108108
"rimraf": "2.6.2",
109109
"rollup": "0.66.6",
110110
"rollup-plugin-babel": "4.0.3",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13051,10 +13051,10 @@ [email protected]:
1305113051
prop-types "^15.3.0"
1305213052
scriptjs "^2.5.8"
1305313053

13054-
react-with-gesture@2.0.4:
13055-
version "2.0.4"
13056-
resolved "https://registry.yarnpkg.com/react-with-gesture/-/react-with-gesture-2.0.4.tgz#3b1095b55b937d0ca89b9d4570bc35c1e3238236"
13057-
integrity sha512-SeXrbhj0NQ/NZh3GhPj6j8OGPGjBem6L79JYf37+AuapMVPuOh9ehoBblhc+C5Yq8aduQn/pB2uB4tKE3LrEAw==
13054+
react-with-gesture@4.0.0:
13055+
version "4.0.0"
13056+
resolved "https://registry.yarnpkg.com/react-with-gesture/-/react-with-gesture-4.0.0.tgz#2ef465e6118c79abc0916368df0de6d1485b2d5d"
13057+
integrity sha512-+7WjnIiqvhW/ViZZxg+kKa9R4evq/PrZuEOo7x/uxWqojPgX1tLfaAlLR+8XlzIS1U0tEJ2ap9nPDe5wOsAccg==
1305813058

1305913059
1306013060
version "16.7.0-alpha.2"

0 commit comments

Comments
 (0)