You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/app/routes/docs.concepts.animated-elements.mdx
+20-20Lines changed: 20 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -19,18 +19,18 @@ export const meta = formatFrontmatterToRemixMeta(frontmatter)
19
19
20
20
## What are they?
21
21
22
-
The basis of `react-spring` depends on two things, `SpringValues` & `animated` components. Lets explore the latter.
22
+
The basis of `react-spring` depends on two things, `SpringValues` & `animated` components. Let's explore the latter.
23
23
An `animated` component receives `SpringValues` through the `style` prop and updates the element without causing a
24
-
react render. It works because it is a [Higher-Order component](https://reactjs.org/docs/higher-order-components.html) (HOC)
24
+
React render. It works because it is a [Higher-Order component](https://reactjs.org/docs/higher-order-components.html) (HOC)
25
25
assigned to a dictionary of elements depending on the target you've selected thus being able to pass the props you
26
26
desire for your application but also containing the logic to interpolate the `SpringValues` from the hook you've used.
27
27
28
28
## Animating elements
29
29
30
30
The `animated` component can be imported from any of our targets. However, an `animated` component is specific to the target
31
-
because they use the native elements of said target. These native elements are elements that are understood by the `react-reconciler`
32
-
of choice e.g. [`@react-three/fiber`](https://github.com/pmndrs/react-three-fiber) is a reconciler for [`three.js`](https://threejs.org/)
33
-
elements. So therefore any element that is understood by the reconciler can be animated.
31
+
because it uses the native elements of said target. These native elements are elements that are understood by the `react-reconciler`
32
+
of choice: e.g. [`@react-three/fiber`](https://github.com/pmndrs/react-three-fiber) is a reconciler for [`three.js`](https://threejs.org/)
33
+
elements. Therefore, any element that the reconciler understands can be animated.
34
34
35
35
```jsx
36
36
import { animated } from'@react-spring/web'
@@ -42,12 +42,12 @@ import { animated } from '@react-spring/web'
42
42
<animated.mesh/>
43
43
```
44
44
45
-
If you've used `framer-motion` before, you will most likely be familiar with the dot notation of accessing a dictionary of components.
45
+
If you used `framer-motion` before, you will most likely be familiar with the dot notation of accessing a dictionary of components.
46
46
47
-
So while being able to use `animated.element` is useful, most cases you'll want to style said element. `react-spring` has no preference on styling techniques,
48
-
common techniques like `css modules` or [`tailwind`](https://tailwindcss.com/)can work because every animated element can accept the properties of the native element, e.g. `className`.
47
+
So, while being able to use `animated.element` is useful, in most cases you'll want to style said element. `react-spring` has no preference about styling techniques:
48
+
common techniques like `css modules` or [`tailwind`](https://tailwindcss.com/)all work, because every animated element accepts the properties of the native element, e.g. `className`.
49
49
50
-
If you're using a css-in-js library to style your components then typically you'll have access to a `styled` function. Just like composing components you can compose
50
+
If you're using a CSS-in-JS library to style your components, you'll typically have access to a `styled` function. Just like composing components you can compose
Sometimes it's not possible to animate an element directly e.g. because it comes from another library, for example[`radix-ui`](https://www.radix-ui.com/).
67
-
Because `animated` is a HOC we can simply wrap our components with it and assuming the component you're wrapping passes to the `style` prop to the native element.
66
+
Sometimes it's impossible to animate an element directly because it comes from another library, like[`radix-ui`](https://www.radix-ui.com/).
67
+
Because `animated` is a HOC, we can simply wrap our components with it, assuming the component you're wrapping passes to the `style` prop to the native element.
68
68
69
69
```jsx
70
70
// This comes from another library e.g. radix-ui
@@ -282,29 +282,29 @@ const Title = styled(Dialog.Title, {
282
282
### How does it work?
283
283
284
284
Higher-order components have access to the props you're passing to the child. Therefore,
285
-
the `animated` component is able to scan through the passed `style` prop and handle said values.
286
-
How the component handles the style prop is dependant of the target you're using. For the
287
-
purpose of explanation, we'll focus on the `web` target.
285
+
the `animated` component can scan through the passed `style` prop and handle said values.
286
+
How the component handles the style prop is dependent on the target you're using.
287
+
Let's concentrate on the `web` target for the sake of explanation.
288
288
289
-
We start by extracting the whole `style` prop and wrapping it in an `AnimatedStyle` class, this
289
+
We start by extracting the whole `style` prop and wrapping it in an `AnimatedStyle` class; this
290
290
class is unique to the `web` target and handles the shorthands for transformations and in theory
291
-
could handle a multitude of interpolations if we were to add them. Once we've performed the specific
292
-
target alterations to the style prop we call the `super` of it's class `AnimatedObject` which then runs
291
+
could handle a multitude of interpolations if we were to add them. Once we performed the specific
292
+
target alterations to the style prop we call the `super` of its class `AnimatedObject`, which then runs
293
293
through the object making the values "animated".
294
294
295
295
### How does it update the native element without causing a react render?
296
296
297
-
Similar to how the `style` prop is handled with regards to it being specific to the target, how we apply
297
+
Similar to how the `style` prop is handled in a target-specific manner, how we apply
298
298
the animated values to the native element is also specific to the target. In the instance of the `web` target,
299
-
we in the process of wrapping the element in the `animated` HOC attach a ref to the element.
299
+
during the process of wrapping the element in the `animated` HOC we attach a `ref` to the element.
300
300
301
301
We are then able to directly change the DOM node imperatively. For further reading, check out [`Controller`](/docs/concepts/controllers-and-springs#Controller).
302
302
303
303
### How can I make my own animated components?
304
304
305
305
Because animated components belong to the target, to create your own registry of animated components
306
306
e.g. for a [D3](https://d3js.org/) react renderer, you would need to use the `createHost` function
307
-
exported from the `@react-spring/animated` package. The signature for which looks like:
307
+
exported from the `@react-spring/animated` package. Its signature looks like this:
0 commit comments