Skip to content

Trigger animation in one component based on action in another [was: Properly triggering a toggled animation using a passed property] #1282

Answered by odewahn
odewahn asked this question in Support
Discussion options

You must be logged in to vote

After a bit more tweaking, I was able to make this work and thought I'd post the solution for future reference. Basically, the solution is to make the item you want to animate a custom component, as described in https://www.react-spring.io/docs/hooks/basics.

import React, { useState, useEffect } from 'react';
import { useSpring, animated } from 'react-spring';

import css from './spring.css';

const Box = (props) => {
  const spring = useSpring({
    transform: props.data.expanded ? `scale(1.1)` : `scale(1)`,
    opacity: props.data.expanded ? 1 : 0.5,
    boxShadow: `0px 3px 8px 0px rgba(0, 0, 0, 0.30)`,
    config: {
      tension: 600, // How much tension is on the spring
      mass: 2…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by odewahn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant