--- meta: title: SpringRef | React Spring 'og:title': SpringRef | React Spring 'twitter:title': SpringRef | React Spring description: An advanced API guide to the SpringRef function in React Spring. 'og:description': An advanced API guide to the SpringRef function in React Spring. 'twitter:description': An advanced API guide to the SpringRef function in React Spring. 'og:url': https://www.react-spring.dev/docs/advanced/spring-ref 'twitter:url': https://www.react-spring.dev/docs/advanced/spring-ref sidebar_position: 5 --- import { formatFrontmatterToRemixMeta } from '../helpers/meta' export const meta = formatFrontmatterToRemixMeta(frontmatter) # SpringRef Our imperative API. You can initialise it via function call, or for better practice use the hook `useSpringRef`. For more contextual information for this function and why it's so important, see [here](/docs/concepts/imperative-api). ## Usage ### Hook ```ts import { animated, useSpring, useSpringRef } from '@react-spring/web' function MyComponent() { const api = useSpringRef() const props = useSpring({ ref: api, from: { opacity: 0 }, to: { opacity: 1 }, }) return Hello World } ``` ### Function call ```ts import { Component, createRef } from 'react' import { Controller, animated, SpringRef } from '@react-spring/web' class AnimatedComponent extends Component { isShowing = createRef(false) api = SpringRef() animations = new Controller({ opacity: 0, ref: this.api }) toggle = () => { this.animations.start({ opacity: this.isShowing ? 1 : 0 }) this.isShowing = !this.isShowing } render() { return ( <> I will fade ) } } ``` ## Properties import { TablesConfiguration } from '../components/Tables/TablesConfig' ## Methods ### Add Add a controller to this ref. ```ts add(ctrl: Controller): void ``` ### Delete Remove a controller from this ref. ```ts delete(ctrl: Controller): void ``` ### Pause Pause some or all animations by passing `SpringValue` keys. ```ts pause(): this pause(keys: OneOrMore): this pause(keys?: OneOrMore): this ``` ### Resume Resume some or all animations by passing `SpringValue` keys. ```ts resume(): this resume(keys: OneOrMore): this resume(keys?: OneOrMore): this ``` ### Set Update the state of each controller without animating. Accepts either a partial state object or a function that returns a partial state object. ```ts set(values: Partial): void set(values: (index: number, ctrl: Controller) => Partial): void ``` ### Start Start the queued animations of each controller. Alternatively pass a `ControllerUpdate` object to update the state of each controller before starting the animations. Or pass a function to edit the `ControllerUpdate` depending on the specific `Controller`. ```ts start(): AsyncResult>[] start(props: ControllerUpdate): AsyncResult>[] start(props: ControllerUpdateFn): AsyncResult>[] start( props?: ControllerUpdate | ControllerUpdateFn ): AsyncResult>[] ``` ### Stop Stop some or all of the animations by passing `SpringValue` keys. Additionall, cancel those animations by passing a `boolean` as the first argument and the `keys` as the second. ```ts stop(): this stop(keys: OneOrMore): this stop(cancel: boolean): this stop(cancel: boolean, keys: OneOrMore): this stop(keys?: OneOrMore): this stop(cancel: boolean, keys?: OneOrMore): this ``` ### Update Add the same props to each controller's update queue. Or alternatively generate separate props for each controller's update queue with a function. ```ts update(props: ControllerUpdate): this update(props: ControllerUpdateFn): this update(props: ControllerUpdate | ControllerUpdateFn): this ```