Download react-spring/docs/app/routes/docs.advanced.controller.mdx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/routes/docs.advanced.controller.mdx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/routes/docs.advanced.controller.mdx
-
curl -L -o docs.advanced.controller.mdx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/routes/docs.advanced.controller.mdx
3.42 kB
| --- | |
| meta: | |
| title: Controller | React Spring | |
| 'og:title': Controller | React Spring | |
| 'twitter:title': Controller | React Spring | |
| description: An advanced API guide to the Controller class in React Spring. | |
| 'og:description': An advanced API guide to the Controller class in React Spring. | |
| 'twitter:description': An advanced API guide to the Controller class in React Spring. | |
| 'og:url': https://www.react-spring.dev/docs/advanced/controller | |
| 'twitter:url': https://www.react-spring.dev/docs/advanced/controller | |
| sidebar_position: 3 | |
| --- | |
| import { formatFrontmatterToRemixMeta } from '../helpers/meta' | |
| export const meta = formatFrontmatterToRemixMeta(frontmatter) | |
| Manages [`SpringValue`s](/docs/advanced/spring-value) for our spring hooks. | |
| Basic usage, the Controller class you initialise can be used as an [`imperative api`](/docs/concepts/imperative-api) | |
| to control your `SpringValues`. Meanwhile you pass `Controller.springs` to your `animated` component. | |
| ```tsx | |
| import { Component, createRef } from 'react' | |
| import { Controller, animated } from '@react-spring/web' | |
| class AnimatedComponent extends Component { | |
| isShowing = createRef(false) | |
| animations = new Controller({ opacity: 0 }) | |
| toggle = () => { | |
| this.animations.start({ opacity: this.isShowing ? 1 : 0 }) | |
| this.isShowing = !this.isShowing | |
| } | |
| render() { | |
| return ( | |
| <> | |
| <button onClick={this.toggle}>click</button> | |
| <animated.div style={this.animations.springs}>I will fade</animated.div> | |
| </> | |
| ) | |
| } | |
| } | |
| ``` | |
| Below is the arguments that can passed to the constructor of the `Controller` class. | |
| ```ts | |
| const ControllerProps = { | |
| ref, | |
| from, | |
| loop, | |
| onStart, | |
| onRest, | |
| onChange, | |
| onPause, | |
| onResume, | |
| onProps, | |
| onResolve, | |
| } | |
| ``` | |
| import { TablesConfiguration } from '../components/Tables/TablesConfig' | |
| import { CONTROLLER_PROPERTIES_DATA } from '../data/fixtures' | |
| <TablesConfiguration data={CONTROLLER_PROPERTIES_DATA} /> | |
| Gets the current values of our springs. | |
| ```ts | |
| get(): State & UnknownProps; | |
| ``` | |
| Set the current values without animating. | |
| ```ts | |
| set(values: Partial<State>): void; | |
| ``` | |
| Push an update onto the queue of each value. | |
| ```ts | |
| update(props: ControllerUpdate<State> | Falsy): this; | |
| ``` | |
| Start the queued animations for every spring, and resolve the returned promise once all queued | |
| animations have finished or been cancelled. When you pass a queue (instead of nothing), that | |
| queue is used instead of the queued animations added with the `update` method, which are left alone. | |
| ```ts | |
| start(props?: OneOrMore<ControllerUpdate<State>> | null): AsyncResult<this>; | |
| ``` | |
| Stop all queued animations for every spring at the same time, or alternatively provide a selection | |
| of keys that should be stopped. | |
| ```ts | |
| stop(): this; | |
| stop(keys: OneOrMore<string>): this; | |
| stop(cancel: boolean): this; | |
| stop(cancel: boolean, keys: OneOrMore<string>): this; | |
| stop(keys?: OneOrMore<string>): this; | |
| stop(cancel: boolean, keys?: OneOrMore<string>): this; | |
| ``` | |
| Freeze the active animation in time. | |
| ```ts | |
| pause(keys?: OneOrMore<string>): this; | |
| ``` | |
| Resume the animation if paused. | |
| ```ts | |
| resume(keys?: OneOrMore<string>): this; | |
| ``` | |
| Call a function once per spring value. | |
| ```ts | |
| each(iterator: (spring: SpringValue, key: string) => void): void | |
| ``` | |