Skip to content

Commit 3710ea2

Browse files
committed
2 parents 1ed866b + 5a2646f commit 3710ea2

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

readme.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ const Header = ({ children, bold, ...styles }) => (
226226
</h1>
227227
)
228228

229-
230229
<Spring render={Header} to={{ color: 'fuchsia' }} bold>
231230
hello there
232231
</Spring>
@@ -236,10 +235,9 @@ Et voilà! `Header` animates on prop changes! Props that `Spring` doesn't recogn
236235

237236
### Native rendering and interpolation ([Demo](https://codesandbox.io/embed/882njxpz29))
238237

239-
| Other animation libs | React-spring |
240-
| -------------- | ----------- |
241-
| ![](assets/without-native.jpeg)   | ![](assets/with-native.jpeg) |
242-
| <sub>Most libraries render animations by having React recalculate the component-tree 60 times per second. Here it attempts to do that to a component consisting of ~300 sub-components, plowing through the browsers frame budget and causing jank.</sub> | <sub>React-spring with the `native` property set to `true` renders the component *only once*, from then on the animation will be applied directly to the dom in a requestAnimationFrame-loop, similar to how gsap and d3 do it.</sub> |
238+
![img](assets/without-native.jpeg) | ![img](assets/with-native.jpeg)
239+
---|---
240+
<sub>Most libraries animate by having React recalculate the component-tree. Here it attempts to animate a component consisting of ~300 sub-components, plowing through the frame budget and causing jank.</sub> | <sub>React-spring with the `native` property renders the component *only once*, from then on the animation will be applied directly to the dom in a requestAnimationFrame-loop, similar to how gsap and d3 do it.</sub>
243241

244242
By default we'll render every frame (like in the image on the left) as it gives you more freedom (for instance this is the only way that you can animate React-component props). In situations where that becomes expensive use the `native` flag. The flag is available for all primitives (Spring, Transition & Trail, Keyframes, Parallax is native by design). **Try doing this in all situations where you can**, the benefits are worth it. Especially if your animated component consists of large subtrees, routes, etc.
245243

@@ -253,18 +251,22 @@ Just be aware of the following conditions:
253251
```jsx
254252
import { Spring, animated, interpolate } from 'react-spring'
255253

256-
<animated.div
257-
style={{
258-
// Use plain animated values like always, ...
259-
borderRadius: radius,
260-
// For interpolations, either call "interpolate" on the value itself, it accepts a function
261-
background: time.interpolate(t => 'rgba(0, 0, 0, ${t})'),
262-
// ... or supply a range clamp
263-
color: time.interpolate({ range: [0, 1], output: ['red', 'rgba(1, 50, 210, 0.5)'] }),
264-
// Or use the interpolate helper, which can take multiple values, it accepts a function
265-
transform: interpolate([x, y], (x, y) => `translate(${x}px, ${y}px)`),
266-
}}>
267-
</animated.div>
254+
<Spring native from={{ radius: 0, time: 0, x: 0, y: 0 }} to={{ radius: 10, time: 1, x: 10, y: 20 }}>
255+
{({ radius, time, x, y }) => (
256+
<animated.div
257+
style={{
258+
// Use plain animated values like always, ...
259+
borderRadius: radius,
260+
// For interpolations, call "interpolate" on the value itself, it accepts a function
261+
background: time.interpolate(t => 'rgba(0, 0, 0, ${t})'),
262+
// ... or supply a range clamp
263+
color: time.interpolate({ range: [0, 1], output: ['red', 'rgba(1, 50, 210, 0.5)'] }),
264+
// Or use generic interpolate, which takes multiple values, it accepts a function
265+
transform: interpolate([x, y], (x, y) => `translate(${x}px, ${y}px)`),
266+
}}>
267+
</animated.div>
268+
)}
269+
</Spring>
268270
```
269271

270272
### Transitions

0 commit comments

Comments
 (0)